-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP12210.cpp
47 lines (46 loc) · 953 Bytes
/
P12210.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
int main() {
int cntB[61], cntS[61];
for(int cas = 1; true; ++cas) {
// Reset and read data:
GI(B); GI(S); if(B == 0 && S == 0) return 0;
memset(cntB, 0, sizeof(cntB));
memset(cntS, 0, sizeof(cntS));
FORI(B) {
GI(b);
++cntB[b];
}
FORI(S) {
GI(s);
++cntS[s];
}
// Run:
for(int b = 60; b >= 2; --b) {
while(cntB[b] > 0) {
// Reduce:
int nearestS = -1000;
for(int s = 2; s <= 60; ++s) {
if(cntS[s] > 0 && ABS(b-s) < ABS(b-nearestS))
nearestS = s;
}
if(nearestS == -1000)
break;
int pairs = min(cntB[b], cntS[nearestS]);
cntB[b] -= pairs;
cntS[nearestS] -= pairs;
}
}
// Output:
int oldestB = -1;
LL left = 0;
for(int b = 60; b >= 2; --b) {
if(cntB[b] > 0) {
oldestB = b;
}
left += cntB[b];
}
cout << "Case " << cas << ": " << left;
if(oldestB != -1)
cout << " " << oldestB;
cout << endl;
}
}