제출 #872569

#제출 시각아이디문제언어결과실행 시간메모리
872569vjudge1Sure Bet (CEOI17_sure)C++17
100 / 100
109 ms3624 KiB
//author: Ahmet Alp Orakci
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

#define ONLINE_JUDGE
void solve() {
    int n;
    cin >> n;

    double a[n], b[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }

    sort(a, a + n);
    sort(b, b + n);

    double ans = 0, calc1 = 0, calc2 = 0;
    int ptr1 = n -1, ptr2 = n -1, al = 0;
    while(ptr1 >= 0 || ptr2 >= 0) {
        if(calc1 <= calc2) {
            if(ptr1 >= 0) {
                calc1 += a[ptr1];
                ptr1--;
            } else {
                calc2 += b[ptr2];
                ptr2--;
            }
        } else {
            if(ptr2 >= 0) {
                calc2 += b[ptr2];
                ptr2--;
            } else {
                calc1 += a[ptr1];
                ptr1--;
            }
        }

        al++;
        ans = max(ans, min(calc1, calc2) - al);
    }

    printf("%.4lf", double(ans));
    
    return;
}

signed main() {
    #ifndef ONLINE_JUDGE
        freopen(".in", "r", stdin);
        freopen(".out", "w", stdout);
    #endif

    int t = 1; //cin >> t;
    for(int i = 1; i <= t; i++) {
        solve();
    }

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...