//https://csacademy.com/contest/ceoi-2017-day-1/task/sure-bet/
#include<bits/stdc++.h>
const int N = 1e5 + 5;
using namespace std;
int n;
double a[N], b[N], ans;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
sort(a+1, a+1+n, greater <double> ()); sort(b+1, b+1+n, greater <double> ());
for (int i = 1; i <= n; i++) a[i] += a[i-1], b[i] += b[i-1];
for (int i = 1; i <= 2*n; i++){
int l = max(i-n, 0), r = min(n, i);
while (l != r){
int mid = (l + r) >> 1;
if (a[mid] >= b[i-mid]) r = mid;
else l = mid+1;
}
ans = max(ans, min(a[l], b[i-l]) - i);
if (l > 0 && i-l < n) ans = max(ans, min(a[l-1], b[i-l+1]) - i);
}
cout << fixed << setprecision(4) << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
356 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
356 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
127 ms |
3356 KB |
Output is correct |
18 |
Correct |
84 ms |
3216 KB |
Output is correct |
19 |
Correct |
85 ms |
3360 KB |
Output is correct |
20 |
Correct |
87 ms |
3300 KB |
Output is correct |
21 |
Correct |
91 ms |
3704 KB |
Output is correct |
22 |
Correct |
83 ms |
3196 KB |
Output is correct |
23 |
Correct |
86 ms |
3320 KB |
Output is correct |
24 |
Correct |
87 ms |
3320 KB |
Output is correct |
25 |
Correct |
89 ms |
3320 KB |
Output is correct |
26 |
Correct |
94 ms |
3576 KB |
Output is correct |