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 + 5;
double a[N], b[N];
int main()
{
int n;
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);
reverse(a + 1, a + n + 1);
sort(b + 1, b + n + 1);
reverse(b + 1, b + n + 1);
int j = 1; double sa = 0, sb = 0, ans = 0, now;
for (int i = 1; i <= n; i++)
{
sa += a[i];
sb -= 1.0;
now = min(sa, sb);
ans = max(ans, now);
int jj = j;
while (jj <= n)
{
if (min(sa - 1.0, sb + b[jj]) > now)
{
sa -= 1.0;
sb += b[jj];
now = min(sa, sb);
jj++;
}
else
break;
}
ans = max(ans, now);
j = jj;
}
cout << fixed << setprecision(4) << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |