/// tree bends in youth
/// 24 .10.2023
/// success is doing same thing in every single day!!!
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
using namespace std;
const ll N =2e5+ 5;
const ll NN =2e6 + 5;
const ll INF = -1e1;
const ll MOD = 1e9 + 7;
const ll LG = 18;
const ll k = 316;
int n;
long double a[N],b[N],pl[N],pr[N];
void solve(){
cin >> n;
for(int i = 1;i <= n;i++){
cin >> a[i] >> b[i];
}
sort(a + 1,a + n + 1);
sort(b + 1,b + n + 1);
reverse(a + 1,a+ n + 1);
reverse(b + 1,b + n + 1);
for(int i = 1;i <= n;i++){
pr[i] = pr[i - 1] + b[i];
pl[i] = pl[i - 1] + a[i];
}
long double ans = 0;
for(int i = 1;i <= n;i++){
if(pl[i] < i)break;
int l = 1,r = n;
while(l < r){
int mid = (l + r) / 2;
if(pl[i] < (long double)(i + mid))r = mid - 1;
long double sum = i + mid;
long double res = min(pl[i] - sum,pr[mid] -sum );
if(res < ans)r = mid;
else l = mid + 1;
ans= max(ans,res);
}
}
cout <<fixed << setprecision(6) <<ans;
}
main (){
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
ll abd= 1;
// cin >> abd;
for(ll i = 1;i <= abd;i++){
// cout << "Case " << i << ":\n";
solve();
}
}
Compilation message
sure.cpp:48:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
48 | main (){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |