forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloowater.cpp
44 lines (37 loc) · 994 Bytes
/
loowater.cpp
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int k, h;
while(cin >> h >> k && k != 0 && h != 0) {
vector<int> knights;
vector<int> heads;
for(int i = 0; i < h; i++) {
int temp;
cin >> temp;
heads.push_back(temp);
}
for(int i = 0; i < k; i++) {
int temp;
cin >> temp;
knights.push_back(temp);
}
int total = 0;
sort(knights.begin(), knights.end());
sort(heads.begin(), heads.end());
while(knights.size() > 0 && heads.size() > 0) {
if(knights[0] >= heads[0]) {
heads.erase(heads.begin());
total += knights[0];
}
knights.erase(knights.begin());
}
if(heads.size() > 0) {
cout << "Loowater is doomed!" << endl;
}
else {
cout << total << endl;
}
}
}