Submission #904003

#TimeUsernameProblemLanguageResultExecution timeMemory
904003Dec0DeddSure Bet (CEOI17_sure)C++14
100 / 100
101 ms6844 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;

const int N = 1e5+10;
const int K = 1e4;

ld a[N], b[N], p[N];
ll n;

ld genx() {
    ld x=0, sm=0;
    for (ll i=1; i<=n; ++i) {
        sm+=a[i];

        ll lf=0, rf=n, res=0;
        while (lf <= rf) {
            ll m=(lf+rf)/2;
            if (sm-m >= p[m]-i) lf=m+1, res=m;
            else rf=m-1; 
        }

        ld val=max(min(sm-res, p[res]-i), min(sm-(res+1), p[res+1]-i));
        x=max(x, val);
    } return x;
}

void solve() {
    cin>>n;
    for (int i=1; i<=n; ++i) {
        cin>>a[i]>>b[i]; --a[i], --b[i];
    } sort(a+1, a+n+1, greater<ld>()), sort(b+1, b+n+1, greater<ld>());
    for (int i=1; i<=n+1; ++i) p[i]=p[i-1]+b[i];

    ld ans=genx();
    swap(a, b);

    p[0]=0;
    for (int i=1; i<=n+1; ++i) p[i]=p[i-1]+b[i];
    ans=max(ans, genx());
    printf("%.4lf", (double)ans);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int t=1;
    while (t--) solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...