Submission #1126491

#TimeUsernameProblemLanguageResultExecution timeMemory
1126491vladiliusSure Bet (CEOI17_sure)C++20
0 / 100
0 ms324 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n; cin>>n;
    vector<double> a(n + 1), b(n + 1);
    for (int i = 1; i <= n; i++){
        cin>>a[i]>>b[i];
    }
    
    sort(a.begin() + 1, a.end(), greater<double>());
    sort(b.begin() + 1, b.end(), greater<double>());
    
    vector<double> mx(n + 1);
    for (int i = 1; i <= n; i++){
        a[i] += a[i - 1];
        b[i] += b[i - 1];
        mx[i] = max(mx[i - 1], (b[i] - i));
    }
    
    vector<double> :: iterator it;
    
    double out = 0;
    for (int i = 1; i <= n; i++){
        it = lower_bound(b.begin() + 1, b.end(), a[i]);
        int j = (int) (it - b.begin());
        
        out = max(out, a[i] - (i + j));
        out = max(out, mx[j - 1] - i);
    }

    printf("%.4lf", out);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...