#include <bits/stdc++.h>
using namespace std;
//#define int long long
const int N = 1e5;
int n;
double f[N + 5], se[N + 5], prefix[N + 5];
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) cin >> f[i] >> se[i];
sort(f + 1, f + n + 1, greater<double>());
sort(se + 1, se + n + 1, greater<double>());
double seValue = se[1];
for (int i = 1; i <= n; i++, seValue += se[i]) prefix[i] = max(prefix[i - 1], seValue - (double)i);
double l = -1e9, r = 1e9, ans = -1e9;
const double eps = 1e-6;
while (r - l > eps) {
double m = (l + r)/2.0, fValue = 0.0;
bool valid = false;
for (int i = 0; i <= n; i++) {
fValue += f[i];
long long rem = min((long long)n, (long long)floor(fValue - m) - i);
if(rem < 0) continue;
valid |= prefix[rem] - (double)i > m || abs(prefix[rem] - (double)i - m) < eps;
}
if (valid) ans = m, l = m;
else r = m;
}
cout << fixed << setprecision(4) << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
284 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
284 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
284 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
73 ms |
2648 KB |
Output is correct |
18 |
Correct |
75 ms |
2644 KB |
Output is correct |
19 |
Correct |
88 ms |
2648 KB |
Output is correct |
20 |
Correct |
74 ms |
2648 KB |
Output is correct |
21 |
Correct |
77 ms |
2536 KB |
Output is correct |
22 |
Correct |
74 ms |
4016 KB |
Output is correct |
23 |
Correct |
77 ms |
3916 KB |
Output is correct |
24 |
Correct |
75 ms |
4008 KB |
Output is correct |
25 |
Correct |
74 ms |
3988 KB |
Output is correct |
26 |
Correct |
77 ms |
4384 KB |
Output is correct |