제출 #1225749

#제출 시각아이디문제언어결과실행 시간메모리
1225749takoshanavaSure Bet (CEOI17_sure)C++20
100 / 100
78 ms1864 KiB
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fs first
#define sc second
using namespace std;

const int N = 100005;
double a[N], b[N];
int n;

signed main() {
    cin >> n;
    for (int i = 1; i <= n; i++)  {
        cin >> a[i] >> b[i];
    }
    sort(a + 1, a + 1 + n);
    reverse(a + 1, a + 1 + n);
    sort(b + 1, b + 1 + n);
    reverse(b + 1, b + 1 + n);
    double ans = 0;
    int cnt1 = 0, cnt2 = 0;
    double sum1 = 0, sum2 = 0;
    while (true) {
        if (cnt1 >= n and cnt2 >= n) break;
        if (cnt1 >= n and cnt2 < n) {
            cnt2++;
            sum2 += b[cnt2];
        }else if(cnt2 >= n and cnt1 < n) {
            cnt1++;
            sum1 += a[cnt1];
        }else if(sum1 <= sum2) {
            cnt1++;
            sum1 += a[cnt1];
        }else{ 
            cnt2++;
            sum2 += b[cnt2];
        }
        ans = max(ans, min(sum1, sum2) - cnt1 - cnt2);
    } 
    cout << fixed << setprecision(4) << ans << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...