-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloowaterDragon.cpp
76 lines (65 loc) · 1.44 KB
/
loowaterDragon.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
ifstream fin("loowaterDragon.in");
ofstream fout("loowaterDragon.out");
int main()
{
while (true)
{
int n, m;
fin >> n >> m;
if (n == 0)
{
break;
}
if (n > m)
{
fout << "Loowater is doomed!\n";
continue;
}
vector<int> heads(n), knights(m);
for (int i = 0; i <= n - 1; ++i)
{
fin >> heads[i];
}
for (int i = 0; i <= m - 1; ++i)
{
fin >> knights[i];
}
sort(heads.begin(), heads.end());
sort(knights.begin(), knights.end());
int total = 0;
int j = 0;
for (int i = 0; j <= n - 1; ++i)
{
if (i == m)
{
total = -1;
fout << "Loowater is doomed!\n";
break;
}
else
{
if (knights[i] >= heads[j])
{
total += knights[i];
++j;
}
}
}
if (total >= 0)
{
fout << total << '\n';
}
}
}