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;
ifstream fin ("gadfadar2.in");
ofstream fout ("gadfadar2.out");
int n;
double a[100002], b[100002];
double f (int na, int nb) {
return min(a[na] - nb, b[nb] - na);
}
int main ()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
a[i] -= 1.0;
b[i] -= 1.0;
}
sort(a + 1, a + n + 1, greater<double>());
sort(b + 1, b + n + 1, greater<double>());
for (int i = 1; i <= n; i++)
a[i] += a[i - 1];
for (int i = 1; i <= n; i++)
b[i] += b[i - 1];
double ans = -1e9;
for (int i = 0; i <= n; i++) {
double val = a[i];
int st = 0, dr = n - 1, p = -1;
while (st <= dr) {
int mid = (st + dr) / 2;
if (f(i, mid) < f(i, mid + 1)) {
p = mid;
st = mid + 1;
}
else
dr = mid - 1;
}
ans = max(ans, f(i, p + 1));
}
cout << fixed << setprecision(4) << ans;
return 0;
}
Compilation message (stderr)
sure.cpp: In function 'int main()':
sure.cpp:33:12: warning: unused variable 'val' [-Wunused-variable]
33 | double val = a[i];
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |