This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define N 100005
double a[N],b[N],ans;
int main(){
int n,i,l,r,mid;
scanf("%d",&n);
for(i=1;i<=n;i++)scanf("%lf %lf",&a[i],&b[i]);
sort(a+1,a+n+1,greater<double>());
sort(b+1,b+n+1,greater<double>());
for(i=1;i<=n;i++)a[i]+=a[i-1],b[i]+=b[i-1];
for(i=1;i<=2*n;i++){
l=0,r=min(i,n);
while(l<=r){
mid=(l+r)/2;
ans=max(ans,min(a[mid],b[min(i-mid,n)])-i);
if(a[mid]>=b[min(i-mid,n)])r=mid-1;
else l=mid+1;
}
}
printf("%.4lf",ans);
return 0;
}
Compilation message (stderr)
sure.cpp: In function 'int main()':
sure.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
9 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
sure.cpp:10:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
10 | for(i=1;i<=n;i++)scanf("%lf %lf",&a[i],&b[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |