답안 #1111106

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1111106 2024-11-11T13:49:05 Z Icelast Sure Bet (CEOI17_sure) C++17
100 / 100
404 ms 5212 KB
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 2*1e5+5, INF = 4e18+9;
const double eps = 1e-6;
void solve(){
    int n;
    cin >> n;
    vector<double> a(n+1), b(n+1);
    for(int i = 1; i <= n; i++){
        cin >> a[i] >> b[i];
    }
    sort(a.begin()+1, a.end(), greater<double>());
    sort(b.begin()+1, b.end(), greater<double>());
    vector<double> pfa(n+2, 0), pfb(n+2, 0);
    for(int i = 1; i <= n; i++){
        pfa[i] = pfa[i-1]+a[i];
        pfb[i] = pfb[i-1]+b[i];
    }
    pfa[n+1] = pfb[n+1] = INF;
    double ans = 0;
    auto cmp = [&](double a, double b) -> bool{
        return b-a > eps;
    };
    auto check = [&](double x, int k) -> bool{
        int pa = lower_bound(pfa.begin()+1, pfa.end(), x) - pfa.begin();
        if(pa == n+1) return false;
        int pb = lower_bound(pfb.begin()+1, pfb.end(), x) - pfb.begin();
        if(pb == n+1) return false;
        return pa+pb <= k;
    };
    for(int i = 1; i <= 2*n; i++){
        double l = 0, r = 1e9;
        while(r-l > eps){
            double mid = (l+r)/2;
            if(check(mid, i)){
                l = mid;
            }else{
                r = mid;
            }
        }
        ans = max(ans, l-i);
    }
    cout << fixed << setprecision(4) << ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}

Compilation message

sure.cpp: In function 'void solve()':
sure.cpp:23:10: warning: variable 'cmp' set but not used [-Wunused-but-set-variable]
   23 |     auto cmp = [&](double a, double b) -> bool{
      |          ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 3 ms 336 KB Output is correct
13 Correct 4 ms 504 KB Output is correct
14 Correct 3 ms 336 KB Output is correct
15 Correct 3 ms 592 KB Output is correct
16 Correct 4 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 3 ms 336 KB Output is correct
13 Correct 4 ms 504 KB Output is correct
14 Correct 3 ms 336 KB Output is correct
15 Correct 3 ms 592 KB Output is correct
16 Correct 4 ms 336 KB Output is correct
17 Correct 364 ms 4940 KB Output is correct
18 Correct 392 ms 4968 KB Output is correct
19 Correct 359 ms 4936 KB Output is correct
20 Correct 340 ms 4812 KB Output is correct
21 Correct 387 ms 5212 KB Output is correct
22 Correct 354 ms 4936 KB Output is correct
23 Correct 346 ms 4960 KB Output is correct
24 Correct 357 ms 4924 KB Output is correct
25 Correct 331 ms 4936 KB Output is correct
26 Correct 404 ms 5192 KB Output is correct