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;
#define ld long double
const int N = 1e5+5;
int n;
ld a[N], b[N], sufB[N];
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cout << fixed << setprecision(10);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
sort(a, a+n);
sort(b, b+n);
sufB[n] = 0;
for (int i = n-1; i >= 0; i--) {
sufB[i] = sufB[i+1] + b[i];
}
ld ans = 0;
ld sumA = 0;
for (int i = n-1; i >= 0; i--) {
sumA += a[i];
int l = 0;
int r = n-1;
while (l < r) {
int mid = (l+r) >> 1;
if (min(sumA, sufB[mid]) - 1 > min(sumA, sufB[mid+1])) r = mid;
else l = mid+1;
}
ans = max(ans, min(sumA, sufB[l]) - (n-i) - (n-l));
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |