#include <bits/stdc++.h>
using namespace std;
#define ld long double
const int N = 1e5+5;
int n;
ld a[N], b[N], sufB[N];
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cout << fixed << setprecision(4);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
sort(a, a+n);
sort(b, b+n);
sufB[n] = 0;
for (int i = n-1; i >= 0; i--) {
sufB[i] = sufB[i+1] + b[i];
}
ld ans = 0;
ld sumA = 0;
for (int i = n-1; i >= 0; i--) {
sumA += a[i];
int l = 0;
int r = n-1;
while (l < r) {
int mid = (l+r) >> 1;
if (sufB[mid] >= sumA) l = mid+1;
else r = mid;
}
ans = max(ans, min(sumA, sufB[l]) - (n-i) - (n-l));
if (l-1 >= 0) ans = max(ans, min(sumA, sufB[l-1]) - (n-i) - (n-l+1));
if (l-2 >= 0) ans = max(ans, min(sumA, sufB[l-2]) - (n-i) - (n-l+2));
}
cout << max((ld)0, ans) << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
2 ms |
4444 KB |
Output is correct |
13 |
Correct |
2 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
2 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
2 ms |
4444 KB |
Output is correct |
13 |
Correct |
2 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
2 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
73 ms |
4948 KB |
Output is correct |
18 |
Correct |
58 ms |
4956 KB |
Output is correct |
19 |
Correct |
62 ms |
4944 KB |
Output is correct |
20 |
Correct |
63 ms |
5100 KB |
Output is correct |
21 |
Correct |
65 ms |
5144 KB |
Output is correct |
22 |
Correct |
54 ms |
5084 KB |
Output is correct |
23 |
Correct |
88 ms |
5080 KB |
Output is correct |
24 |
Correct |
56 ms |
4948 KB |
Output is correct |
25 |
Correct |
55 ms |
5080 KB |
Output is correct |
26 |
Correct |
69 ms |
5064 KB |
Output is correct |