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(int i = a; i<int(b);++i)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define trav(a,c) for(auto a: c)
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;
ll n;
vector<double> a;
vector<double> b;
/*
double best = 0;
void getBest(ll index, double sumA, double sumB){
if(index==n){
best = max(best,min(sumA,sumB));
return;
}
getBest(index+1,sumA+a[index]-2,sumB+b[index]-2);
getBest(index+1,sumA+a[index]-1,sumB-1);
getBest(index+1,sumA-1,sumB+b[index]-1);
getBest(index+1,sumA,sumB);
}*/
int main(){
cin.sync_with_stdio(false);
cin>>n;
a.resize(n);
b.resize(n);
rep(i,0,n) cin>>a[i]>>b[i];
//getBest(0,0,0);
sort(all(a));
sort(all(b));
reverse(all(a));
reverse(all(b));
vector<double> sumA(n+1);
rep(i,0,n) sumA[i+1] = sumA[i] + a[i];
vector<double> sumB(n+1);
rep(i,0,n) sumB[i+1] = sumB[i] + b[i];
double best = 0;
rep(i,1,n+1){
ll bi = lower_bound(all(sumB),sumA[i])-sumB.begin();
rep(j,bi-1,bi+2){
if(j<1||j>n) continue;
best = max(best,min(sumA[i]-i-j,sumB[j]-i-j));
}
}
printf("%.4lf",(double)best);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |