제출 #1245742

#제출 시각아이디문제언어결과실행 시간메모리
1245742inkvizytorSure Bet (CEOI17_sure)C++20
100 / 100
112 ms16108 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

void change(int v, int x, vector<int> &tr) {
    v += 1<<18;
    tr[v] = x;
    while (v > 1) {
        v /= 2;
        tr[v] = max(tr[v*2], tr[v*2+1]);
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<double> a (n, 0), b (n, 0);
    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>());
    vector<double> pa(n+1, 0), pb (n+1, 0);
    set<pair<double, int>> sa, sb;
    for (int i = 1; i <= n; i++) {
        pa[i] = pa[i-1]+a[i-1];
        pb[i] = pb[i-1]+b[i-1];
        sa.insert({pa[i], i});
        sb.insert({pb[i], i});
    }
    double sc = 0;
    for (int i = 1; i <= n; i++) {
        auto x = sb.lower_bound({pa[i], 0});
        if (x != sb.end()) {
            sc = max(sc, pa[i]-i-(*x).second);
        }
        auto y = sa.lower_bound({pb[i], 0});
        if (y != sa.end()) {
            sc = max(sc, pb[i]-i-(*y).second);
        }
    }
    printf("%.4lf",(double)sc);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...