#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 time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |