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 int long long
#define pb push_back
const long long INF=1e17,N=2e5+6;
main(){
int n;cin>>n;
vector<long double> a(n),b(n);
for(int i=0;i<n;i++)
cin>>a[i]>>b[i];
sort(a.rbegin(),a.rend());
sort(b.rbegin(),b.rend());
long double ans=0,A=0,B=0;
int l=1,r=1;
A+=a[0],B+=b[0];
ans=min(A-2,B-2);
while(l<n || r<n){
if(l<n && r<n){
if(A<B)
A+=a[l++];
else
B+=b[r++];
}
else if(l<n)
A+=a[l++];
else
B+=b[r++];
ans=max(ans,min(A-l-r,B-l-r));
}
cout<<fixed<<setprecision(6)<<ans<<endl;
}
/*
5 1
lkjhg
polir
*/
Compilation message (stderr)
sure.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
6 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |