Submission #1152403

#TimeUsernameProblemLanguageResultExecution timeMemory
1152403asdasdSure Bet (CEOI17_sure)C++20
100 / 100
59 ms2224 KiB
//gm  --- akezhon
#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define pb push_back
#define pf push_front
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define tm (tl+tr)/2
#define TL v+v, tl, tm
#define TR v+v+1, tm+1, tr
#define DA l <= tl && tr <= r
#define NE r < tl || tr < l
// #define double long double
#define int long long
using namespace std;

const int N=2e5+7;
const int mod=998244353;
const int inf=2e18;

void AlemAmenov(){
    int n;
    cin >> n;
    vector<double>a, b;
    for(int i=1; i <= n; i++){
        double x, y;
        cin >> x >> y;
        a.pb(x);
        b.pb(y);
    }
    a.pb(0);
    b.pb(0);
    sort(all(a));
    sort(all(b));
    reverse(a.begin()+1, a.end());
    reverse(b.begin()+1, b.end());
    for(int i=1; i <= n; i++){
        a[i]+=a[i-1];
        b[i]+=b[i-1];
    }
    double ans=0;
    for(int i=1; i <= n; i++){
        int l=1, r=n;
        while(l <= r){
            int m1=l+(r-l)/3;
            int m2=r-(r-l)/3;
            double x = min(a[i]-i-m1, b[m1]-i-m1);
            double y = min(a[i]-i-m2, b[m2]-i-m2);
            ans = max({ans, x, y});
            if(x < y)l=m1+1;
            else r=m2-1;
        }
    }
    cout << fixed << setprecision(4) << ans;
}
signed main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int RealName=1;
    // cin >> RealName;
    // srand(time(0));

    while(RealName--)
        AlemAmenov();
    
return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...