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;
typedef long long ll;
double a[100005],b[100005],ans;
int n;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i]>>b[i];
sort(a+1,a+n+1);
reverse(a+1,a+n+1);
sort(b+1,b+n+1);
reverse(b+1,b+n+1);
for(int i=1;i<=n;i++)
a[i]+=a[i-1];
for(int i=1;i<=n;i++)
b[i]+=b[i-1];
for(int i=1;i<=n;i++)
{
int st=1;
int dr=n;
int pozmin=n+1;
while(st<=dr)
{
int mij=(st+dr)/2;
if(b[mij]>=a[i])
{
pozmin=mij;
dr=mij-1;
}
else
st=mij+1;
}
if(pozmin>n)
continue;
double x=a[i]-i-pozmin;
ans=max(ans,x);
}
for(int i=1;i<=n;i++)
{
int st=1;
int dr=n;
int pozmin=n+1;
while(st<=dr)
{
int mij=(st+dr)/2;
if(a[mij]>=b[i])
{
pozmin=mij;
dr=mij-1;
}
else
st=mij+1;
}
if(pozmin>n)
continue;
double x=b[i]-i-pozmin;
ans=max(ans,x);
}
cout<<fixed<<setprecision(4)<<ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |