#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;
int cur=0;
for(int x=0;x<n;x++){
//int cur=0;
counter+=arr[x];
//show(counter,counter);
while(cur<n-1&&prefix[cur]<counter){
cur++;
}
//show(cur,cur);
best=max(best,min(counter-(ld)(cur+x+2),prefix[cur]-(ld)(cur+x+2)));
if(cur<n-1){
best=max(best,min(counter-(ld)(cur+x+3),prefix[cur+1]-(ld)(cur+x+3)));
}
//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();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |