UVa 11292-Dragon of Loowater
1203 ワード
リンク:
http://uva.onlinejudge.org/index.php?option=com_オンラインjudge&Itemid=8&category=24&page=show_problem&problem=2267
http://uva.onlinejudge.org/index.php?option=com_オンラインjudge&Itemid=8&category=24&page=show_problem&problem=2267
/*
《 - 》 1
+
by shuangde
*/
#include<cstdio>
#include<algorithm>
#define REP(i, n) for(int i=0; i<(n); ++i)
using namespace std;
const int MAXN = 20005;
int dia[MAXN], cost[MAXN];
int main(){
int n, m;
while(~scanf("%d%d",&n,&m) && n+m){
REP(i, n) scanf("%d", &dia[i]);
REP(i, m) scanf("%d", &cost[i]);
sort(dia, dia+n);
sort(cost, cost+m);
int ans=0, cur=0;
REP(i, m) {
if(dia[cur]<=cost[i]){
ans += cost[i];
++cur;
}
if(cur == n) break;
}
if(cur == n){
printf("%d
", ans);
}
else{
puts("Loowater is doomed!");
}
}
return 0;
}