#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<int(n);i++)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define dforn(i,n) for(int i=int(n)-1;i>=0;i--)
#define dforsn(i,s,n) for(int i=int(n)-1;i>=int(s);i--)
#define sz(c) int((c).size())
#define all(c) begin(c), end(c)
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
#define fst first
#define snd second
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
vector<ld> a(n),b(n);
forn(i,n) cin>>a[i]>>b[i];
sort(all(a)),sort(all(b));
reverse(all(a)),reverse(all(b));
ld sumA=0,sumB=0;
int i=0,j=0;
ld res=0;
while(i<n&&j<n){
if(sumA<sumB||(sumA==sumB&&a[i]>b[j])){
sumA+=a[i++];
}else{
sumB+=b[j++];
}
res=max(res,min(sumA,sumB)-i-j);
}
while(i<n){
sumA+=a[i++];
res=max(res,min(sumA,sumB)-i-j);
}
while(j<n){
sumB+=b[j++];
res=max(res,min(sumA,sumB)-i-j);
}
printf("%.4lf",(double)res);
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... |