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>
using namespace std;
int main() {
int n; cin >> n;
vector<double> a(n), b(n), pref(n);
for(int i=0; i<n; i++) cin >> a[i] >> b[i];
sort(a.rbegin(), a.rend());
sort(b.rbegin(), b.rend());
pref[0] = b[0];
for(int i=1; i<n; i++) pref[i] = pref[i-1] + b[i];
double l=0, r=1e9, ans=0;
while(r - l > 1e-6) {
double mid = (l + r) / 2;
bool ok = 0;
double sum1 = 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(pref[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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |