Submission #1331915

#TimeUsernameProblemLanguageResultExecution timeMemory
1331915uranhishigSure 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, 0.0);
    vector<double> pb(n + 1, 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 y = 0;
    for (int x = 0; x <= n; x++) {
        while (y < n and pb[y + 1] <= pa[x]) {
            y++;
        }
        ans = max(ans, min(pa[x], pb[y]) - x - y);
        if (y + 1 <= n) {
            ans = max(ans, min(pa[x], pb[y + 1]) - x - y - 1);
        }
    }
    cout << fixed << setprecision(9) << ans << endl;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...