Submission #1261949

#TimeUsernameProblemLanguageResultExecution timeMemory
1261949new_accSure Bet (CEOI17_sure)C++20
100 / 100
47 ms2224 KiB
#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    vector <double> pie = {}, dru = {};
    int n;
    cin>>n;
    double p1, p2;
    for (int i = 0; i<n; i++){
        cin>>p1>>p2;
        pie.push_back(p1);
        dru.push_back(p2);
    }
    sort(pie.begin(), pie.end(), greater());
    sort(dru.begin(), dru.end(), greater());
    double w = 0, pl1 = 0, pl2 = 0, ind1 = 0, ind2 = 0;
    while(ind1<n && ind2 < n){
        while(ind1<n && pl1 <= pl2){
            pl1 += pie[ind1]-1;
            pl2 -= 1;
            w = max(w, min(pl1, pl2));
            ind1++;
        }
        while(ind2<n && pl2 <= pl1){
            pl2 += dru[ind2]-1;
            pl1-=1;
            w = max(w, min(pl1, pl2));
            ind2++;
        }
    }
    while(ind1<n && pl1 <= pl2){
        pl1 += pie[ind1]-1;
        pl2 -= 1;
        w = max(w, min(pl1, pl2));
        ind1++;
    }
    cout<<fixed<<setprecision(4)<<w<<"\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...