Submission #796199

# Submission time Handle Problem Language Result Execution time Memory
796199 2023-07-28T07:44:14 Z Sandarach151 Sure Bet (CEOI17_sure) C++17
100 / 100
78 ms 5168 KB
#include<bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    double arr1[n];
    double arr2[n];
    for(int i=0; i<n; i++){
        cin >> arr1[i] >> arr2[i];
    }
    sort(arr1, arr1+n, greater<double>());
    sort(arr2, arr2+n, greater<double>());
    double pref1[n];
    double pref2[n];
    pref1[0]=arr1[0]-1;
    pref2[0]=arr2[0]-1;
    for(int i=1; i<n; i++){
        pref1[i]=pref1[i-1]+arr1[i]-1;
        pref2[i]=pref2[i-1]+arr2[i]-1;
    }
    double maxx = 0;
    for(int i=0; i<n; i++){
        if(pref1[i]<=0){
            break;
        }
        else{
            // find first position such that pref1[i]-b<pref2[b]-i
            int pos1 = 0;
            int pos2 = n-1;
            while(pos1<pos2){
                int mid = (pos1+pos2)/2;
                if(pref1[i]-mid<=pref2[mid]-i){
                    pos2 = mid;
                }
                else{
                    pos1=mid+1;
                }
            }
            maxx = max(maxx, min(pref1[i]-pos1, pref2[pos1]-i)-1);
            if(pos1>0){
                maxx = max(maxx, min(pref1[i]-(pos1-1), pref2[pos1-1]-i)-1);
            }
            if(pos1<n-1){
                maxx = max(maxx, min(pref1[i]-(pos1+1), pref2[pos1+1]-i)-1);
            }
        }
    }
    printf("%.4lf",(double) maxx);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 62 ms 4768 KB Output is correct
18 Correct 62 ms 4772 KB Output is correct
19 Correct 78 ms 4728 KB Output is correct
20 Correct 66 ms 4796 KB Output is correct
21 Correct 70 ms 5168 KB Output is correct
22 Correct 69 ms 4768 KB Output is correct
23 Correct 69 ms 4796 KB Output is correct
24 Correct 71 ms 4776 KB Output is correct
25 Correct 63 ms 4768 KB Output is correct
26 Correct 69 ms 5168 KB Output is correct