This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |