답안 #841780

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
841780 2023-09-02T05:18:37 Z vjudge1 Sure Bet (CEOI17_sure) C++17
100 / 100
70 ms 5292 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;

const int maxn = 1e5 + 5;

int n;
double a[maxn], b[maxn];
double sum_1[maxn], sum_2[maxn];
double kq;

bool cmp(double a, double b)
{
    return (a > b);
}

bool check(int mid, int id)
{
    double cur = sum_1[id] - (mid + id);
    double val = sum_2[mid] - (mid + id);

    if(val >= cur)
        return true;
    return false;
}

signed main()
{
//    freopen("B.inp", "r", stdin);
//    freopen("B.out", "w", stdout);

    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    cin >> n;
    for(int i=1 ; i<=n ; ++i){
        cin >> a[i] >> b[i];
    }

    sort(a+1, a+1+n, cmp);
    sort(b+1, b+1+n, cmp);

    for(int i=1 ; i<=n ; ++i){
        sum_1[i] = sum_1[i-1] + a[i];
        sum_2[i] = sum_2[i-1] + b[i];
    }

    for(int i=1 ; i<=n ; ++i){
        int l=0;
        int r=n;

        while(r - l > 1){
            int mid = l + r >> 1;
            if(check(mid, i)){
                r = mid;
            }
            else{
                l = mid;
            }
        }

        double val = min(sum_2[r] - (r + i), sum_1[i] - (r + i));
        kq = max(kq, val);
        if(r > 1){
            val = min(sum_2[r-1] - (r + i - 1), sum_1[i] - (r + i - 1));
            kq = max(kq, val);
        }
    }

   cout << setprecision(4) << fixed << kq;
}

/// code by yourlove ///

Compilation message

sure.cpp: In function 'int main()':
sure.cpp:52:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   52 |             int mid = l + r >> 1;
      |                       ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 2 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 2 ms 2396 KB Output is correct
17 Correct 66 ms 4764 KB Output is correct
18 Correct 67 ms 4692 KB Output is correct
19 Correct 68 ms 4760 KB Output is correct
20 Correct 70 ms 4780 KB Output is correct
21 Correct 70 ms 5204 KB Output is correct
22 Correct 68 ms 4692 KB Output is correct
23 Correct 69 ms 4692 KB Output is correct
24 Correct 69 ms 4692 KB Output is correct
25 Correct 67 ms 4948 KB Output is correct
26 Correct 70 ms 5292 KB Output is correct