#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;
long long n, i, j, cnt;
long long a[100010], b[100010], suma, sumb, ans = 0;
long double x;
bool descCmp(long long x, long long y)
{
return x > y;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (i = 1; i <= n; i++) {
cin >> x;
x *= 10000LL;
a[i] = round(x);
cin >> x;
x *= 10000LL;
b[i] = round(x);
}
sort(a+1, a+n+1, descCmp);
sort(b+1, b+n+1, descCmp);
i = j = 1;
for (cnt = 1; cnt <= 2*n; cnt++) {
if (i == n+1 || (j <= n && sumb + b[j] <= suma)) {
sumb += b[j++];
}
else {
suma += a[i++];
}
ans = max(ans, min(suma, sumb) - 10000LL * cnt);
if (i > 1 && j <= n) {
ans = max(ans, min(suma - a[i-1], sumb + b[j]) - 10000LL * cnt);
}
}
x = ans;
x /= 10000LL;
cout << fixed << setprecision(4);
cout << x;
return 0;
}
# |
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 |
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 |
344 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 |
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 |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
61 ms |
1996 KB |
Output is correct |
18 |
Correct |
61 ms |
1840 KB |
Output is correct |
19 |
Correct |
62 ms |
1876 KB |
Output is correct |
20 |
Correct |
62 ms |
1876 KB |
Output is correct |
21 |
Correct |
68 ms |
3724 KB |
Output is correct |
22 |
Correct |
61 ms |
3148 KB |
Output is correct |
23 |
Correct |
62 ms |
3388 KB |
Output is correct |
24 |
Correct |
70 ms |
3408 KB |
Output is correct |
25 |
Correct |
65 ms |
3192 KB |
Output is correct |
26 |
Correct |
65 ms |
3568 KB |
Output is correct |