-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path11292.cpp
More file actions
32 lines (26 loc) · 810 Bytes
/
11292.cpp
File metadata and controls
32 lines (26 loc) · 810 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
29
30
31
32
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n, m, in;
vector<int> heads, knights;
int main() {
while (cin >> n >> m and n and m) {
heads.clear();
knights.clear();
for (int i = 0; i < n; i++) { cin >> in; heads.push_back(in); }
for (int i = 0; i < m; i++) { cin >> in; knights.push_back(in); }
sort(knights.begin(), knights.end());
sort(heads.begin(), heads.end());
int gold = 0;
bool solved = true;
for (int i = 0; i < heads.size() and solved; i++) {
auto it = lower_bound(knights.begin(), knights.end(), heads[i]);
if (it == knights.end()) solved = false;
else { gold += *it; knights.erase(it); }
}
if (solved) cout << gold << endl;
else cout << "Loowater is doomed!" << endl;
}
return 0;
}