답안 #1042761

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1042761 2024-08-03T10:50:18 Z fryingduc Sure Bet (CEOI17_sure) C++17
100 / 100
55 ms 4436 KB
//#pragma GCC optimize("Ofast,unroll-loops") 
#include "bits/stdc++.h"
using namespace std;

#ifdef duc_debug
#include "bits/debug.h"
#else 
#define debug(...)     
#endif

//#define int long long

const int maxn = 1e5+5;
int n;
double a[maxn], b[maxn];
double ps[maxn];

int check(int mid, int argentina, double sum){
    double left = min(sum - argentina + 1, ps[n] - ps[n - mid + 1] - argentina + 1);
    double right = min(sum - argentina - 1, ps[n] - ps[n - mid - 1] - argentina - 1);
    double cur = min(sum - argentina, ps[n] - ps[n -  mid] - argentina);
    if(cur > left and cur > right) return 0;
    else{
        if(cur < left) return 2;
        else return 1;
    }
}

void solve(){
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> a[i] >> b[i];
    }
    sort(a + 1, a + n + 1);
    sort(b + 1, b + n + 1);
    ps[n + 1] = 0;
    for(int i = 1; i <= n; ++i){
        ps[i] = ps[i - 1] + b[i];
    }
    double ans = 0, sum = 0;
    for(int i = n; i; --i){
        sum += a[i];
        int l = 1, r = n;
        while(l <= r){
            int mid = (l + r) / 2;
            int argentina = (n - i + 1) + mid;
            if(check(mid, argentina, sum) == 1){
                l = mid + 1;
            }
            else if(check(mid, argentina, sum) == 2){
                r = mid - 1;
            }
            else{
                ans = max(ans, min(sum - argentina, ps[n] - ps[n - mid] - argentina));
                break;
            }
            debug(i, mid, ans);
        }
        // ans = max(ans, rodi);
    }
    cout << fixed << setprecision(4) << ans;
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int test = 1;
    // cin >> test;
    for(int i = 1; i <= test; i++){
      // cout << "Case " << "#" << i << ": "; 
      solve();
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 50 ms 3932 KB Output is correct
18 Correct 51 ms 3976 KB Output is correct
19 Correct 51 ms 4132 KB Output is correct
20 Correct 49 ms 3920 KB Output is correct
21 Correct 51 ms 4436 KB Output is correct
22 Correct 49 ms 3928 KB Output is correct
23 Correct 52 ms 3920 KB Output is correct
24 Correct 49 ms 3972 KB Output is correct
25 Correct 55 ms 3932 KB Output is correct
26 Correct 51 ms 4360 KB Output is correct