Submission #866748

#TimeUsernameProblemLanguageResultExecution timeMemory
866748nghia0912Sure Bet (CEOI17_sure)C++17
100 / 100
102 ms5304 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...