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 ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl;
typedef pair<int,int>pii;
typedef pair<pii,pii>pi2;
void solve(){
int n;
cin >> n;
ld arr[n];
ld arr2[n];
for(int x=0;x<n;x++){
cin >> arr[x] >> arr2[x];
if(arr[x]<1.0) arr[x]=1.0;
if(arr2[x]<1.0) arr2[x]=1.0;
}
sort(arr,arr+n,greater<ld>());
sort(arr2,arr2+n,greater<ld>());
ld prefix[n];
ld counter=0.0;
for(int x=0;x<n;x++){
counter+=arr2[x];
prefix[x]=counter;
}
ld best=0.0;
counter=0.0;
for(int x=0;x<n;x++){
int l=0;
int r=n-1;
int mid;
int cur=0;
counter+=arr[x];
//show(counter,counter);
while(l<=r){
mid=(l+r);
ld hold=counter-(ld)(x+mid+2); //winning for arr
ld win=prefix[mid]-(ld)(x+mid+2); //winning for arr2
if(hold>=win){
cur=mid;
l=mid+1;
}
else r=mid-1;
}
//show(cur,cur);
best=max(best,min(counter-(ld)(cur+x+2),prefix[cur]-(ld)(cur+x+2)));
if(cur<n-1) cur++;
best=max(best,min(counter-(ld)(cur+x+2),prefix[cur]-(ld)(cur+x+2)));
//show(best,best);
}
cout << fixed << setprecision(4) << best;
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
//freopen("redistricting.in", "r", stdin);
//freopen("redistricting.out", "w", stdout);
int t=1;
//cin >> t;
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |