제출 #872565

#제출 시각아이디문제언어결과실행 시간메모리
872565vjudge1Sure Bet (CEOI17_sure)C++17
60 / 100
2001 ms3244 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;
    for(int i = 0; i <= n * 2; i++) {
        double calc1 = 0, calc2 = 0;
        int ptr1 = n -1, ptr2 = n -1;
        for(int j = 0; j < i; j++) {
            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--;
                }
            } 
        }

        //cerr << i << " :: " << calc1 << " " << calc2 << "\n";
        ans = max(ans, min(calc1, calc2) - i);
    }

    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...