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;
const int N = 1e5 + 10;
int n;
double a[N], b[N], ans = -1e9;
double calc(int i, int j) {
return min(a[i], b[j]) - i - j;
}
void divide(int L, int R, int from, int to) {
if (L > R) return;
int mid = L + R >> 1;
double cur = -1e9;
int best = from;
for (int i = from; i <= to; ++i) {
if (calc(mid, i) > cur) {
cur = calc(mid, i);
best = i;
}
}
ans = max(ans, cur);
divide(L, mid - 1, from, best);
divide(mid + 1, R, best, to);
}
int main() {
ios :: sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i] >> b[i];
sort(a + 1, a + n + 1);
reverse(a + 1, a + n + 1);
sort(b + 1, b + n + 1);
reverse(b + 1, b + n + 1);
for (int i = 1; i <= n; ++i) a[i] += a[i - 1], b[i] += b[i - 1];
divide(0, n, 0, n);
cout << setprecision(4) << fixed << ans;
}
Compilation message (stderr)
sure.cpp: In function 'void divide(int, int, int, int)':
sure.cpp:16:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
16 | int mid = L + R >> 1;
| ~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |