链接
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=24&problem=2267&mosmsg=Submission+received+with+ID+15876651
code
注意事项,先排序,后比较,注意\n输出
code
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 20005;
int A[maxn],B[maxn];
int main()
{
int n ,m;
while(scanf("%d%d",&n,&m)==2 && n && m)
{
for(int i = 0 ; i < n ; i ++) scanf("%d",&A[i]);
for(int j = 0 ; j < m ; j ++) scanf("%d",&B[j]);
sort(A,A+n);
sort(B,B+m);
int cost = 0,cursor = 0,index=0;
for(int i = 0 ; i < m ;i ++)
{
if(B[i] >= A[cursor])
{
cost += B[i];
cursor ++;
}
if(cursor == n) break;
}
if(cursor < n)
printf("Loowater is doomed!\n");
else
printf("%d\n",cost);
}
return 0;
}