Submission #1331898

#TimeUsernameProblemLanguageResultExecution timeMemory
1331898uranhishigSure Bet (CEOI17_sure)C++20
0 / 100
0 ms344 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    int n;
    cin >> n;
    vector<double> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());
    vector<double> pa(n + 1);
    vector<double> pb(n + 1);
    for (int i = 0; i <= n; i++) {
        pa[i] = 0.0;
    }
    for (int i = 0; i <= n; i++) {
        pb[i] = 0.0;
    }
    for (int i = 1; i <= n; i++) {
        pa[i] = pa[i - 1] + a[i - 1];
        pb[i] = pb[i - 1] + b[i - 1];
    }
    double ans = 0.0;
    int l = 0;
    int r = 0;
    for (int i = 1; i <= 2 * n; i++) {
        if (l < n and (pa[l] <= pb[r])) {
            l++;
        } 
        else {
            r++;
        }
        ans = max(ans, min(pa[l], pb[r]) - i);
    }
    cout << fixed << setprecision(9) << ans;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...