Skip to content

Commit

Permalink
11292 solved
Browse files Browse the repository at this point in the history
  • Loading branch information
ksaveljev committed May 24, 2011
1 parent 7260bdb commit 6c6d373
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions 11292.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <iostream>
#include <algorithm>
using namespace std;

int main(void) {
int n, m;
int heads[20000];
int knights[20000];

while (cin >> n >> m) {
if (n == 0 && m == 0)
break;

for (int i = 0; i < n; i++)
cin >> heads[i];

for (int i = 0; i < m; i++)
cin >> knights[i];

if (m < n) {
cout << "Loowater is doomed!" << endl;
continue;
}

sort(heads, heads + n);
sort(knights, knights + m);

int result = 0;

int cur = 0;
for (int i = 0; i < n; i++) {
if (n - i > m - cur) {
result = -1;
break;
}
for (int j = cur; j < m; j++) {
if (knights[j] < heads[i]) {
cur++;
continue;
}

result += knights[j];
cur++;
break;
}
}

if (result == -1) {
cout << "Loowater is doomed!" << endl;
} else {
cout << result << endl;
}
}

return 0;
}

0 comments on commit 6c6d373

Please sign in to comment.