Submission #1365092

#TimeUsernameProblemLanguageResultExecution timeMemory
1365092msab3fSure Bet (CEOI17_sure)C++20
100 / 100
75 ms1980 KiB
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 100'000 + 10;

int n;
vector<double> a, b;
double ans;

int main() {
    cin >> n;

    a.resize(n);
    b.resize(n);

    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }

    sort(a.begin(), a.end(), greater<>());
    sort(b.begin(), b.end(), greater<>());

    for (int i = 1; i < n; ++i) {
        a[i] += a[i - 1];
        b[i] += b[i - 1];
    }

    for (int i = 1; i <= n; ++i) {
        int x = int(lower_bound(b.begin(), b.end(), a[i - 1]) - b.begin());
        if (x != n) {
            ans = max(ans, a[i - 1] - i - 1 - int(lower_bound(b.begin(), b.end(), a[i - 1]) - b.begin()));
        }
        x = int(lower_bound(a.begin(), a.end(), b[i - 1]) - a.begin());
        if (x != n) {
            ans = max(ans, b[i - 1] - i - 1 - int(lower_bound(a.begin(), a.end(), b[i - 1]) - a.begin()));
        }
    }

    cout << fixed << setprecision(4) << ans << '\n';
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...