forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmali.cpp
54 lines (43 loc) · 915 Bytes
/
mali.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
#include <bits/stdc++.h>
using namespace std;
int calc(vector<int> v1, vector<int> v2) {
int p1 = 0;
int p2 = 100;
int worst = 0;
bool broken = false;
while(true) {
while(v1[p1] == 0) {
p1++;
if(p1 > 100) {
broken = true;
break;
}
}
while(v2[p2] == 0) {
p2--;
if(p2 < 0) {
broken = true;
break;
}
}
if(broken) break;
worst = max(worst, p1+p2);
int m = min(v1[p1], v2[p2]);
v1[p1] -= m;
v2[p2] -= m;
}
return worst;
}
int main() {
int n;
cin >> n;
vector<int> v1(101,0);
vector<int> v2(101,0);
for(int i = 0; i < n; i++) {
int n1, n2;
cin >> n1 >> n2;
v1[n1]++;
v2[n2]++;
cout << calc(v1,v2) << endl;
}
}