#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define yy cout<<"YES"<<endl;
#define nn cout<<"NO"<<endl;
#define ld long double
#define T ll t;cin>>t;while(t--){solve();}
#define funfact for(ll i=1 ; i<=n ; i++){cout<<a[i]<<" ";}
using namespace std;
const ll N=2e5,mod=1e9+7,inf=1e18;
ld a[N],b[N];
ld prea[N],preb[N];
ll n;
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
bool cmp (ld x,ld y)
{
return x>y;
}
ld f(ll x,ll y)
{
return min(prea[x]-1.0*y,preb[y]-1.0*x);
}
ld bin(ll x)
{
ll l=1,r=n;
ld ans=-1;
if(n == 1) return f(x, 1);
if(n == 2) return max(f(x, 1), f(x, 2));
while (l<=r)
{
ll md=(l+r)/2;
ll fi=md-1,se=md,th=md+1;
if (fi==0)
{
ans=md,l=md+1;
continue;
}
if (th==n+1)
{
ans=md,r=md-1;
//continue;
}
if (f(x,fi)<=f(x,se)&&f(x,se)<=f(x,th))
{
ans=md+1,l=md+1;
}
else if (f(x,fi)>=f(x,se)&&f(x,se)>=f(x,th))
{
ans=md-1,r=md-1;
}
else if (f(x,fi)<=f(x,se)&&f(x,se)>=f(x,th))
{
return f(x,se);
}
}
return f(x,ans);
}
void solve(){
cin>>n;
for (ll i=1;i<=n;i++)
{
cin>>a[i]>>b[i];
a[i]--;
b[i]--;
}
sort(a+1,a+n+1,cmp);
sort(b+1,b+n+1,cmp);
ld ans=0.0;
for (ll i=1;i<=n;i++){
prea[i]+=prea[i-1]+a[i];
preb[i]+=preb[i-1]+b[i];}
for (ll i=n;i>=1;i--)
{
ans=max(ans,bin(i));
}
cout<<fixed<<setprecision(4)<<ans<<endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
}
/* This code is created by anhluong
-------Copy code is prohibiited in any form
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
0 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
0 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
0 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
95 ms |
11348 KB |
Output is correct |
18 |
Correct |
94 ms |
11348 KB |
Output is correct |
19 |
Correct |
103 ms |
11224 KB |
Output is correct |
20 |
Correct |
102 ms |
11348 KB |
Output is correct |
21 |
Correct |
106 ms |
11220 KB |
Output is correct |
22 |
Correct |
96 ms |
11344 KB |
Output is correct |
23 |
Correct |
95 ms |
11232 KB |
Output is correct |
24 |
Correct |
103 ms |
11344 KB |
Output is correct |
25 |
Correct |
100 ms |
11348 KB |
Output is correct |
26 |
Correct |
105 ms |
11344 KB |
Output is correct |