Submission #866748

# Submission time Handle Problem Language Result Execution time Memory
866748 2023-10-27T02:06:44 Z nghia0912 Sure Bet (CEOI17_sure) C++17
100 / 100
102 ms 5304 KB
#define COPYRIGHT CODE BY TRINH TUAN NGHIA
#include<bits/stdc++.h>
#define Boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long
#define endl "\n"
#define st first
#define nd second
#define ii pair <ll,ll>
#define iii pair <ll,ii>
#define iiii pair <ii,ii>
#define pb push_back
#define NAME "bet"
using namespace std;
const ll N = 1e5 + 10;
int n;
double a[N], b[N];
double sa[N], sb[N];
double ans = 0;
void inp (){
    cin >> n;
    for (int i =1 ; i <= n; ++i){
        cin >> a[i] >> b[i];
    }
    sort(a + 1, a + n + 1, greater<double>());
    sort(b + 1, b + n + 1, greater<double>());
    for (int i = 1; i <= n; ++i){
        sa[i] = sa[i - 1] + a[i];
        sb[i] = sb[i - 1] + b[i];
        //cout <<a[i] << " " << sa[i] << endl;
    }
}
void solve(){
    double l = 0, r = 1e9 +7;
    for (int i = 1; i <= 60; ++i){
        double mid = (l + r) / 2;
        bool check = false;
        double temp = 0, temp2 = 0;
        int pos = 0, pos2 = 0;
        for (int j = 0;j <= 2 * n; ++j){

            while (temp -  j < mid and pos < n){
                temp = sa[++pos];
            }
            while (temp2 - j < mid and pos2 < n){
                temp2 = sb[++pos2];
            }
            if (pos + pos2 <= j and temp - j >= mid and temp2 - j >= mid){
                    //if (mid == 9,4)cout << temp << endl;
                    check = true;
            }
        }
        if (check){
            l = mid;
            ans = max(ans, mid);
        }
        else r = mid;

        //cout << mid << endl;
    }
    cout << setprecision(4) << fixed << ans << endl;
}
signed main (){
    if (fopen(NAME".inp", "r")){
        freopen(NAME".inp", "r", stdin);
        freopen(NAME".out", "w", stdout);
    }
    Boost;
    inp();
    solve();
}
/*
input

*/

/*
output

*/

Compilation message

sure.cpp: In function 'int main()':
sure.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen(NAME".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sure.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen(NAME".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2512 KB Output is correct
12 Correct 1 ms 2528 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 2 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2512 KB Output is correct
12 Correct 1 ms 2528 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 2 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 93 ms 4692 KB Output is correct
18 Correct 97 ms 4692 KB Output is correct
19 Correct 102 ms 4932 KB Output is correct
20 Correct 93 ms 4692 KB Output is correct
21 Correct 96 ms 5132 KB Output is correct
22 Correct 99 ms 4932 KB Output is correct
23 Correct 96 ms 4688 KB Output is correct
24 Correct 98 ms 4944 KB Output is correct
25 Correct 92 ms 4772 KB Output is correct
26 Correct 93 ms 5304 KB Output is correct