当前位置: 代码迷 >> 综合 >> Uva 11292 Dragon of Loowater (贪心)
  详细解决方案

Uva 11292 Dragon of Loowater (贪心)

热度:44   发布时间:2023-12-17 03:37:54.0

题意:

见训练指南

思路:

sort后小到大贪心,这里贪心既能保证不浪费,还能保证经费最优

错误及反思:

代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn = 20010;
int head[maxn];
int knig[maxn];
int main()
{int n,m;while(scanf("%d%d",&n,&m)&&n&&m){for(int i=0;i<n;i++)scanf("%d",&head[i]);for(int i=0;i<m;i++)scanf("%d",&knig[i]);sort(head,head+n);sort(knig,knig+m);int ans=0,i=0,j=0;bool judge=false;for(;i<n;i++){if(j==m){judge=true; break;}for(;j<m;j++){if(knig[j]>=head[i]){ans+=knig[j++];break;}}}if(judge) printf("Loowater is doomed!\n");else printf("%d\n",ans);}
}