Submission #1146919

#TimeUsernameProblemLanguageResultExecution timeMemory
1146919overwatch9Sure Bet (CEOI17_sure)C++17
100 / 100
75 ms1984 KiB
#include <bits/stdc++.h>
using namespace std;
int 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.begin(), a.end(), greater <double> ());
    sort(b.begin(), b.end(), greater <double> ());

    double ans = 0;
    int l = 0, r = 0;
    double suma = 0, sumb = 0, tot = 0;
    while (l < n || r < n) {
        if ((suma < sumb && l < n) || r >= n) {
            suma += a[l];
            tot++;
            l++;
        } else {
            sumb += b[r];
            tot++;
            r++;
        }
        ans = max(ans, min(suma, sumb) - tot);
    }
    cout << fixed << setprecision(4) << ans << '\n';

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...