#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
vector<double> a(n), b(n);
for(int i=0; i<n; i++) cin >> a[i] >> b[i];
sort(a.rbegin(), a.rend());
sort(b.rbegin(), b.rend());
for(int i=1; i<n; i++) b[i] += b[i-1];
double l=0, r=1e9, ans=0;
while(r - l > 1e-6) {
double mid = (l + r) / 2, sum1 = 0;
bool ok = 0;
for(int i=0; i<n&&!ok; i++) {
sum1 += a[i];
if(sum1 - i - 2 < mid) continue;
int mx = min(n-1, (int)((sum1 - i - 2) - mid));
if(b[mx] - mx - i - 2 >= mid && sum1 - i - 2 - mx >= mid) ok = 1;
}
if(ok) ans = l = mid;
else r = mid;
}
cout << setprecision(4) << fixed << ans << '\n';
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 |
600 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 |
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 |
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 |
600 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 |
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 |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
75 ms |
1984 KB |
Output is correct |
18 |
Correct |
69 ms |
1884 KB |
Output is correct |
19 |
Correct |
69 ms |
1880 KB |
Output is correct |
20 |
Correct |
69 ms |
1880 KB |
Output is correct |
21 |
Correct |
78 ms |
1884 KB |
Output is correct |
22 |
Correct |
69 ms |
1992 KB |
Output is correct |
23 |
Correct |
68 ms |
1884 KB |
Output is correct |
24 |
Correct |
69 ms |
1884 KB |
Output is correct |
25 |
Correct |
69 ms |
1996 KB |
Output is correct |
26 |
Correct |
87 ms |
1880 KB |
Output is correct |