Submission #124547

# Submission time Handle Problem Language Result Execution time Memory
124547 2019-07-03T13:41:38 Z semiauto Sure Bet (CEOI17_sure) C++14
0 / 100
2 ms 376 KB
#include <bits/stdc++.h>
using namespace std;
int n,i,j,pos;
double s,ans;
double a[100001],b[100001],sum[100001],pre[100001];
int main() {
    cin>>n;
    for (i=1;i<=n;i++)
        cin>>a[i]>>b[i];
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    for (i=1;(2*i)<=n;i++) {
        swap(a[i],a[n-i+1]);
        swap(b[i],b[n-i+1]);
    }
    for (i=1;i<=n;i++) {
        sum[i]=sum[i-1]+b[i];
        pre[i]=max(pre[i-1],sum[i]-i);
    }
    for (i=1;i<=n;i++) {
        s+=a[i];
        pos=0;
        for (j=20;j>=0;j--) {
            if (pos+(1<<j)>n)
                continue;
            if (sum[pos+(1<<j)]<=s)
                pos+=(1<<j);
        }
        if (pos>0)
            ans=max(ans,pre[pos]-i);
        if (pos<=n)
            ans=max(ans,s-pos-1-i);
    }
    cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -