-
Notifications
You must be signed in to change notification settings - Fork 0
/
00978.cpp
88 lines (70 loc) · 2.03 KB
/
00978.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
77
78
79
80
81
82
83
84
85
86
87
88
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){1014
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ll n; cin >> n;
while(n--){
ll B,sg,sb; cin >> B >> sg >> sb;
multiset<ll> g, b;
for(ll i = 0; i < sg; i++){
ll temp; cin >> temp;
g.insert(temp);
}
for(ll i = 0; i < sb; i++){
ll temp; cin >> temp;
b.insert(temp);
}
while(g.size()>0&&b.size()>0){
ll f = min(B, min((ll)g.size(), (ll)b.size()));
queue<ll> qG,qB;
// for(auto x: g){
// cout << x << " ";
// } cout << "\n";
// for(auto x: b){
// cout << x << " ";
// } cout << "\n";
for(ll i = 0; i < f; i++){
ll bigG = *(g.rbegin());
ll bigB = *(b.rbegin());
if(bigG>bigB){
qG.push(bigG-bigB);
}
else if(bigG<bigB){
qB.push(bigB-bigG);
}
g.erase(g.find(bigG)); b.erase(b.find(bigB));
}
while(!qG.empty()){
g.insert(qG.front());
qG.pop();
}
while(!qB.empty()){
b.insert(qB.front());
qB.pop();
}
}
if(g.size()>0){
cout << "green wins\n";
while(!g.empty()){
cout << *(g.rbegin()) << "\n";
g.erase(g.find(*g.rbegin()));
}
}
else if(b.size()>0){
cout << "blue wins\n";
while(!b.empty()){
cout << *(b.rbegin()) << "\n";
b.erase(b.find(*b.rbegin()));
}
}
else{
cout << "green and blue died\n";
}
if(cin.good()) cout << "\n";
}
return 0;
}