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);
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |