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;
typedef long long ll;
const int MAXN = 1e5+5;
double a[MAXN], b[MAXN];
int n;
bool check(double x) {
int l = n, r = n;
double totl = 0, totr = 0;
for (int k = 1; k <= 2*n; ++k) {
if (totl < k+x) {
if (l == 0)
break;
l--;
totl += a[l];
} if (totr < k+x) {
if (r == 0)
break;
r--;
totr += b[r];
}
if (n-l+n-r <= k)
return 1;
}
return 0;
}
int main() {
cin >> n;
for (int i = 0; i < n; ++i)
cin >> a[i] >> b[i];
sort(a, a+n);
sort(b, b+n);
double lo = 0, hi = 1e15;
for (int i = 0; i <= 200; ++i) {
double mid = (lo+hi)/2;
if (check(mid))
lo = mid;
else
hi = mid;
}
cout << fixed << setprecision(4) << lo << 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... |