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>
#define int long long
#define pb push_back
#define x first
#define y second
#define getbit(u,i) ((u>>i)&1)
#define all(x) x.begin(),x.end()
#define N 200001
using namespace std;
typedef pair<int,int> ii;
typedef pair<double,double> dd;
int n;
double a[N],b[N],sa[N],sb[N],ans;
double f(int na,int nb)
{
return min(sa[na]-nb,sb[nb]-na);
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i]>>b[i];
sort(a+1,a+n+1,greater<double>());
sort(b+1,b+n+1,greater<double>());
for(int i=1;i<=n;i++)
{
sa[i]=sa[i-1]+a[i]-1;
sb[i]=sb[i-1]+b[i]-1;
}
for(int i=1;i<=n;i++)
{
int lo=-1,hi=n;
while(hi-lo>1)
{
int mid=(hi+lo)>>1;
if(f(i,mid)>f(i,mid+1)) hi=mid;
else lo=mid;
}
ans=max(ans,f(i,lo+1));
}
cout<<setprecision(4)<<fixed<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |