#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define all(x) (x).begin(), (x).end()
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<double> a(n), b(n);
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
    sort(all(a));
    reverse(all(a));
    sort(all(b));
    reverse(all(b));
    for (int i = 1; i < n; i++) a[i] += a[i - 1];
    for (int i = 1; i < n; i++) b[i] += b[i - 1];
    int r = 0;
    double ans = 0;
    for (int i = 0; i < n; i++) {
        while (b[r] < a[i]) {
            ans = max(ans, b[r] - (i + r + 2));
            r++;
        }
        if (r < n) ans = max(ans, a[i] - (i + r + 2));
        ans = max(ans, b[r - 1] - (i + r + 1));
    }
    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... |