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>
#define int long long
using namespace std;
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n;
cin >> n;
double a[n + 1], b[n + 1];
for (int i = 1; i <= n; i++)
{
cin >> a[i] >> b[i];
}
sort(a + 1, a + n + 1, greater<double>());
sort(b + 1, b + n + 1, greater<double>());
double prefA[n + 1] = {0}, prefB[n + 1] = {0};
prefA[1] = a[1];
prefB[1] = b[1];
for (int i = 2; i <= n; i++)
{
prefA[i] = prefA[i - 1] + a[i];
prefB[i] = prefB[i - 1] + b[i];
}
double ans = 0;
for (int i = 1; i <= n; i++)
{
int l = 1, r = n;
while (r - l > 1)
{
int mid = l + (r - l) / 2;
double valmid = min(prefA[i] - (double)i - (double)mid, prefB[mid] - (double)i - (double)mid);
double valnxt = min(prefA[i] - (double)i - (double)(mid+1), prefB[mid+1] - (double)i - (double)(mid+1));
if (valmid > valnxt)
{
r = mid;
}
else
{
l = mid;
}
}
double vall = min(prefA[i] - (double)i - (double)l, prefB[l] - (double)i - (double)l);
double valr = min(prefA[i] - (double)i - (double)r, prefB[r] - (double)i - (double)r);
if (vall > valr)
{
ans = max(ans, vall);
}
else
{
ans = max(ans, valr);
}
}
cout << fixed << setprecision(4) << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |