#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector <pair <double, double>> nums(n);
for (int i = 0; i < n; i++) {
double a, b;
cin >> a >> b;
nums[i].first = a;
nums[i].second = b;
}
vector <double> a(n), b(n);
for (int i = 0; i < n; i++) {
a[i] = nums[i].first;
b[i] = nums[i].second;
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
double l = 0, r = 0;
double ans = 0;
int pt1 = n-1, pt2 = n-1;
double cnt = 0;
while (cnt < 2 * n) {
if ((l < r && pt1 >= 0) || pt2 < 0) {
l += a[pt1];
pt1--;
} else {
r += b[pt2];
pt2--;
}
cnt++;
ans = max(ans, min(l, r) - cnt);
}
printf("%.4lf", ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 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 |
452 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 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 |
452 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
79 ms |
4688 KB |
Output is correct |
18 |
Correct |
77 ms |
4692 KB |
Output is correct |
19 |
Correct |
76 ms |
4884 KB |
Output is correct |
20 |
Correct |
77 ms |
4688 KB |
Output is correct |
21 |
Correct |
96 ms |
5208 KB |
Output is correct |
22 |
Correct |
78 ms |
4796 KB |
Output is correct |
23 |
Correct |
79 ms |
4928 KB |
Output is correct |
24 |
Correct |
79 ms |
4816 KB |
Output is correct |
25 |
Correct |
79 ms |
4796 KB |
Output is correct |
26 |
Correct |
84 ms |
5300 KB |
Output is correct |