//author: Ahmet Alp Orakci
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define ONLINE_JUDGE
void solve() {
int n;
cin >> n;
double a[n], b[n];
for(int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
sort(a, a + n);
sort(b, b + n);
double ans = 0, calc1 = 0, calc2 = 0;
int ptr1 = n -1, ptr2 = n -1, al = 0;
while(ptr1 >= 0 || ptr2 >= 0) {
if(calc1 <= calc2) {
if(ptr1 >= 0) {
calc1 += a[ptr1];
ptr1--;
} else {
calc2 += b[ptr2];
ptr2--;
}
} else {
if(ptr2 >= 0) {
calc2 += b[ptr2];
ptr2--;
} else {
calc1 += a[ptr1];
ptr1--;
}
}
al++;
ans = max(ans, min(calc1, calc2) - al);
}
printf("%.4lf", double(ans));
return;
}
signed main() {
#ifndef ONLINE_JUDGE
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
int t = 1; //cin >> t;
for(int i = 1; i <= t; i++) {
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
97 ms |
1884 KB |
Output is correct |
18 |
Correct |
91 ms |
3128 KB |
Output is correct |
19 |
Correct |
92 ms |
3156 KB |
Output is correct |
20 |
Correct |
93 ms |
3348 KB |
Output is correct |
21 |
Correct |
103 ms |
3624 KB |
Output is correct |
22 |
Correct |
91 ms |
3156 KB |
Output is correct |
23 |
Correct |
106 ms |
3152 KB |
Output is correct |
24 |
Correct |
95 ms |
3108 KB |
Output is correct |
25 |
Correct |
93 ms |
3156 KB |
Output is correct |
26 |
Correct |
109 ms |
3624 KB |
Output is correct |