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 MAXN = 100005;
 
int n;
double a[MAXN], b[MAXN];
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    double ans = 0;
    cin >> n;
    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>());
    int pt = 0;
    double oa = 0, ob = 0, cur = 0;
    for(int i = 0; i <= n; i++)
    {
        oa += a[i];
        while(pt + 1 <= n and ob + b[pt + 1] < oa)
        {
            pt++;
            ob += b[pt];
            cur = max(cur, ob - pt);
        }
        ans = max(ans, cur - i);
        if(pt + 1 <= n)
        {
            ans = max(ans, oa - pt - 1 - i);
        }
    }
    cout << setprecision(4) << fixed << ans << '\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... |