Submission #1027330

# Submission time Handle Problem Language Result Execution time Memory
1027330 2024-07-19T03:44:43 Z vjudge1 Sure Bet (CEOI17_sure) C++17
100 / 100
112 ms 11344 KB
#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
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4608 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4608 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 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 4444 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4608 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 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 4444 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 105 ms 11216 KB Output is correct
18 Correct 104 ms 11220 KB Output is correct
19 Correct 103 ms 11212 KB Output is correct
20 Correct 101 ms 11228 KB Output is correct
21 Correct 106 ms 11232 KB Output is correct
22 Correct 101 ms 11220 KB Output is correct
23 Correct 107 ms 11344 KB Output is correct
24 Correct 103 ms 11220 KB Output is correct
25 Correct 101 ms 11216 KB Output is correct
26 Correct 112 ms 11220 KB Output is correct