#include <bits/stdc++.h>
#define dbg() cerr <<
#define name(x) (#x) << ": " << (x) << ' ' <<
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
vector<double> a(n), b(n);
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
a[i] -= 1.0; b[i] -= 1.0;
}
sort(a.rbegin(), a.rend());
sort(b.rbegin(), b.rend());
vector<double> sum(n);
for (int i = 0; i < n; ++i) {
sum[i] = b[i];
if (i != 0) sum[i] += sum[i - 1];
}
double ans = 0.0, sum_a = 0.0;
for (int cnt_a = 1; cnt_a <= n; ++cnt_a) {
auto Compute = [&](int cnt_b) {
return min(sum_a - cnt_b, sum[cnt_b - 1] - cnt_a);
};
sum_a += a[cnt_a - 1];
int lo = 1, hi = n, res = 0;
while (lo <= hi) {
int one = lo + (hi - lo) / 3;
int two = hi - (hi - lo) / 3;
if (Compute(one) <= Compute(two)) {
res = two;
lo = one + 1;
} else {
res = one;
hi = two - 1;
}
}
// dbg() name(cnt_a) name(res) name(sum_a) name(sum[res - 1]) name(Compute(res)) endl;
ans = max(ans, Compute(res));
}
cout << fixed << setprecision(4) << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
1 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
1 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
4 ms |
380 KB |
Output is correct |
16 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
1 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
4 ms |
380 KB |
Output is correct |
16 |
Correct |
4 ms |
376 KB |
Output is correct |
17 |
Correct |
131 ms |
4028 KB |
Output is correct |
18 |
Correct |
118 ms |
4088 KB |
Output is correct |
19 |
Correct |
133 ms |
4232 KB |
Output is correct |
20 |
Correct |
117 ms |
4188 KB |
Output is correct |
21 |
Correct |
130 ms |
4516 KB |
Output is correct |
22 |
Correct |
124 ms |
4088 KB |
Output is correct |
23 |
Correct |
125 ms |
4132 KB |
Output is correct |
24 |
Correct |
125 ms |
4128 KB |
Output is correct |
25 |
Correct |
122 ms |
4088 KB |
Output is correct |
26 |
Correct |
130 ms |
4596 KB |
Output is correct |