답안 #849513

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
849513 2023-09-14T21:35:41 Z Benmath Sure Bet (CEOI17_sure) C++14
100 / 100
122 ms 5996 KB
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;
int n;
double prvi[100010];
double drugi[100010];   
double prefiks[100010][3];
double sumiraj(int indeks, int koji){
    if(indeks == 0){
        return prefiks[n-1][koji];
    }else{
        return (prefiks[n-1][koji] - prefiks[indeks-1][koji]);
    }
}
int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> prvi[i];
        cin >> drugi[i];
    }
    sort(prvi, prvi+n);
    sort(drugi,drugi+n);
    double suma_prva = 0;
    double suma_druga = 0;
    prefiks[0][0] = prvi[0];
    prefiks[0][1] = drugi[0];
    for(int i = 1; i < n; i++){
        for (int j = 0; j < 2; j++){
            prefiks[i][j] = prefiks[i-1][j];
            if(j == 0){
                prefiks[i][j] += prvi[i];
            }else{
                prefiks[i][j] += drugi[i];
            }
        }
    }
    double ans = 0;
    for(int i = n-1; i>=0; i--){
        suma_prva = suma_prva + prvi[i];
        double broj_prvih = n-i;
        double broj_drugih = -1;
        int l = 0;
        int r = n-1;
        while (l <= r){
            int mid = (l+r) / 2;
            double mid1 = mid;
            if(sumiraj(mid,1) >= suma_prva){
                broj_drugih = max(broj_drugih , mid1);
                l = mid + 1;
            }else{
                r = mid - 1;
            }
        }
        broj_drugih = n - broj_drugih;
        if (broj_drugih != (n+1)){
             double rezultat = suma_prva - broj_prvih - broj_drugih;
            ans = max(ans, rezultat);
           // cout << ans << " "<<broj_prvih << " "<< broj_drugih << endl;
        }
    }
     for(int i = n-1; i>=0; i--){
        suma_druga = suma_druga + drugi[i];
        double broj_drugih = n-i;
        double broj_prvih = -1;
        int l = 0;
        int r = n-1;
        while (l <= r){
            int mid = (l+r) / 2;
            double mid1 = mid;
            if(sumiraj(mid,0) >= suma_druga){
                broj_prvih = max(broj_prvih,mid1);
                l = mid + 1;
            }else{
                r = mid - 1;
            }
        }
        broj_prvih = n - broj_prvih;
        if (broj_prvih != (n+1)){
            double rezultat = suma_druga - broj_prvih - broj_drugih;
            ans = max(ans, rezultat);
        }
    }
    
 printf("%.4lf",(double)ans);

}
  
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 452 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
# 결과 실행 시간 메모리 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 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 452 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 109 ms 5456 KB Output is correct
18 Correct 109 ms 5508 KB Output is correct
19 Correct 107 ms 5456 KB Output is correct
20 Correct 104 ms 5464 KB Output is correct
21 Correct 118 ms 5996 KB Output is correct
22 Correct 108 ms 5684 KB Output is correct
23 Correct 106 ms 5688 KB Output is correct
24 Correct 122 ms 5692 KB Output is correct
25 Correct 103 ms 5464 KB Output is correct
26 Correct 118 ms 5920 KB Output is correct