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 double ld;
int n;
ld a[100001];
ld b[100001];
ld pref[100001];
int main () {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
sort(a + 1, a + n + 1);
sort(b + 1, b + n + 1);
reverse(a + 1, a + n + 1);
reverse(b + 1, b + n + 1);
ld mx = 0;
for (int i = 2; i <= n; i++) {
a[i] += a[i - 1];
b[i] += b[i - 1];
}
pref[1] = a[1] - 1;
for (int i = 2; i <= n; i++) {
pref[i] = max(pref[i - 1], a[i] - i);
}
for (int i = 1; i <= n; i++) {
int l = 1, r = n, ans = -1;
while (l <= r) {
int mid = (l + r) >> 1;
if (a[mid] < b[i]) {
l = mid + 1;
} else {
r = mid - 1; ans = mid;
}
}
if (ans != -1) {
mx = max(mx, b[i] - i - ans);
if (ans != -1) mx = max(mx, pref[ans - 1] - i);
} else {
mx = max(mx, pref[n] - i);
}
}
cout << fixed << setprecision(4) << mx << '\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... |