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 rep(i,a,b) for(ll i = a; i<ll(b); i++)
#define trav(x,s) for(auto &x: s)
#define all(v) v.begin(),v.end()
#define sz(v) ll(v.size())
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;
int main(){
ll n;
cin>>n;
vector<double> a(n);
vector<double> b(n);
rep(i,0,n) cin>>a[i]>>b[i];
sort(all(a));
reverse(all(a));
sort(all(b));
reverse(all(b));
ll ia = 0;
ll ib = 0;
double sa = 0;
double sb = 0;
double ans = 0;
while(true){
if(sb<sa && ib<n){
sb += b[ib];
ib++;
//cout<<"sb: "<<sb<<endl;
} else if(ia<n){
sa += a[ia];
ia++;
//cout<<"sa: "<<sa<<endl;
} else {
//cout<<"breaking"<<endl;
break;
}
//cout<<ia<<" "<<ib<<endl;
//cout<<min(sb,sa)-ia-ib<<endl;
ans = max(ans,min(sb,sa)-ia-ib);
}
printf("%.4lf\n",(double)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... |