版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lvxiangyu11/article/details/79964704
#include<iostream>
#include<algorithm>
int monster[20010];
int knights[20010];
using namespace std;
int main() {
int x, y;
cin >> x >> y;
while (x!=0 || y!=0) {
for (int i = 0; i < x; i++)
cin>>monster[i];
for (int i = 0; i < y; i++)
cin >>knights[i];
sort(monster,monster+x);
sort(knights, knights + y);
int cost = 0;
int monsterPtr = 0;
bool nag = false;
for (int i = 0; i < y; i++) {
if (monsterPtr > x-1) {
goto end;
}
if (knights[i] >= monster[monsterPtr]) {
monsterPtr++;
cost += knights[i];
if (monsterPtr == x) {
cout << cost << endl;
nag = true;
goto end;
}
}
}
end:
if (nag == false)
cout << "Loowater is doomed!" << endl;
cin >> x >> y;
}
return 0;
}