제출 #1369462

#제출 시각아이디문제언어결과실행 시간메모리
1369462aleksandreSure Bet (CEOI17_sure)C++20
100 / 100
34 ms1996 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define vii vector <int>
#define endl '\n'
#define lb lower_bound
#define ub upper_bound
const int inf = 1e18;
const int N = 2e5+5;
inline void test_case() {
    int n;
    cin >> n;
    double a[n+5],b[n+5];
    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>());
    double ans = 0;
    int l = 0;
    int r = 0;
    double a1 = 0, b1 = 0;
    while (true) {
        if (l >= n && r >= n) break;
        if (l >= n && r < n) {
            r++;
            b1 += b[r];
        } else if (r >= n && l < n) {
            l++;
            a1 += a[l];
        } else if (a1 <= b1) {
            l++;
            a1 += a[l];
        } else { 
            r++;
            b1 += b[r];
        }
        ans = max(ans,min(a1,b1)-l-r);
    }
    printf("%.4lf",(double)ans);
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int T = 1;
    // cin >> T;
    while (T--) test_case();
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…