Submission #124553

#TimeUsernameProblemLanguageResultExecution timeMemory
124553semiautoSure Bet (CEOI17_sure)C++14
100 / 100
231 ms5232 KiB
#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); } printf("%.4f\n",ans); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...