题意:
见训练指南
思路:
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);}
}