forked from paulot/uva
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11292.cpp
More file actions
28 lines (23 loc) · 650 Bytes
/
Copy path11292.cpp
File metadata and controls
28 lines (23 loc) · 650 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <algorithm>
#include <iostream>
using namespace std;
int heads[20000], knights[20000];
int main() {
int n, m;
while (cin >> n >> m and (n != 0 or m != 0)) {
for (int i = 0; i < n; i++) cin >> heads[i];
for (int i = 0; i < m; i++) cin >> knights[i];
sort(heads, heads+n);
sort(knights, knights+m);
int k = 0, price = 0;
bool ok = true;
for (int i = 0; i < n; i++) {
while(k < m and knights[k] < heads[i]) k++;
if (k >= m) { ok = false; break; }
else { price += knights[k], k++; }
}
if (ok) cout << price << endl;
else cout << "Loowater is doomed!" << endl;
}
return 0;
}