제출 #299012

#제출 시각아이디문제언어결과실행 시간메모리
299012istleminSure Bet (CEOI17_sure)C++14
100 / 100
250 ms2432 KiB
#include <bits/stdc++.h>

using namespace std;

#define rep(i,a,b) for(ll i = a; i<ll(b); i++)
#define trav(x,s) for(auto &x: s)
#define all(v) v.begin(),v.end()
#define sz(v) ll(v.size())

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;

int main(){
    ll n;
    cin>>n;
    vector<double> a(n);
    vector<double> b(n);
    rep(i,0,n) cin>>a[i]>>b[i];

    sort(all(a));
    reverse(all(a));
    sort(all(b));
    reverse(all(b));

    ll ia = 0;
    ll ib = 0;
    double sa = 0;
    double sb = 0;

    double ans = 0;

    while(true){
        if(sb<sa && ib<n){
            sb += b[ib];
            ib++;
            //cout<<"sb: "<<sb<<endl;
        } else if(ia<n){
            sa += a[ia];
            ia++;
            //cout<<"sa: "<<sa<<endl;
        } else {
            //cout<<"breaking"<<endl;
            break;
        }
        //cout<<ia<<" "<<ib<<endl;
        //cout<<min(sb,sa)-ia-ib<<endl;
        ans = max(ans,min(sb,sa)-ia-ib);
    }
    
    printf("%.4lf\n",(double)ans);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...