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 ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
signed main(){
int n;
cin>>n;
vector <long double> a(n),b(n);
for(int i=0;i<n;i++){
cin>>a[i]>>b[i];
a[i]--;b[i]--;
}
sort(all(a));sort(all(b));
reverse(all(a));reverse(all(b));
long double p1=0,p2=0;
long double sum1=0,sum2=0;
long double ans=0;
while(p1<n){
sum1+=a[p1];
p1++;
while(min(sum1-p2,sum2-p1)<=min(sum1-p2-1,sum2+b[p2]-p1) && p2<n){
sum2+=b[p2];
p2++;
}
ans=max(ans,min(sum1-p2,sum2-p1));
}
cout<<fixed<<setprecision(4)<<ans<<"\n";
}
/*
4
1.4 3.7
1.2 2
1.6 1.4
1.9 1.5
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |