Submission #960262

# Submission time Handle Problem Language Result Execution time Memory
960262 2024-04-10T05:33:40 Z irmuun Sure Bet (CEOI17_sure) C++17
100 / 100
75 ms 5200 KB
#include<bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
 
int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    vector<double>a(n),b(n);
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
    }
    sort(rall(a));
    sort(rall(b));
    vector<double>sa(n+1),sb(n+1);
    sa[0]=0;
    sb[0]=0;
    for(int i=0;i<n;i++){
        sa[i+1]=sa[i]+a[i];
        sb[i+1]=sb[i]+b[i];
    }
    double ans=0;
    for(int i=1;i<=n;i++){
        int l=0,r=i;
        while(l<r){
            int mid=(l+r+1)/2;
            if(sa[mid]<=sb[i-mid]){
                l=mid;
            }
            else{
                r=mid-1;
            }
        }
        ans=max(ans,sa[l]-i);
        if(l<i){
            ans=max(ans,sb[i-l-1]-i);
        }
    }
    for(int i=n+1;i<=2*n;i++){
        int l=i-n,r=n;
        if(sa[l]<=sb[n]){
            while(l<r){
                int mid=(l+r+1)/2;
                if(sa[mid]<=sb[i-mid]){
                    l=mid;
                }
                else{
                    r=mid-1;
                }
            }
            ans=max(ans,sa[l]-i);
            if(l<n){
                ans=max(ans,sb[i-l-1]-i);
            }
        }
        else{
            while(l<r){
                int mid=(l+r+1)/2;
                if(sb[mid]<=sa[i-mid]){
                    l=mid;
                }
                else{
                    r=mid-1;
                }
            }
            ans=max(ans,sb[l]-i);
            if(l<n){
                ans=max(ans,sa[i-l-1]-i);
            }
        }
    }
    printf("%.4f",ans);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 63 ms 4948 KB Output is correct
18 Correct 69 ms 4944 KB Output is correct
19 Correct 63 ms 4920 KB Output is correct
20 Correct 65 ms 4944 KB Output is correct
21 Correct 75 ms 5200 KB Output is correct
22 Correct 63 ms 4952 KB Output is correct
23 Correct 63 ms 4916 KB Output is correct
24 Correct 63 ms 4812 KB Output is correct
25 Correct 65 ms 4948 KB Output is correct
26 Correct 68 ms 5200 KB Output is correct