답안 #986936

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
986936 2024-05-21T15:26:03 Z Alebn Sure Bet (CEOI17_sure) C++14
100 / 100
154 ms 3664 KB
#include <bits/stdc++.h>

using namespace std;

int n;
vector<double> a, b;

bool srt(double x, double y) {
    if(x == 0) return true;
    if(y == 0) return false;
    return x > y;
}

int main() {
    cin >> n;
    a = vector<double>(n + 1), b = vector<double>(n + 1);
    for(int i = 1; i <= n; i++) cin >> a[i] >> b[i];
    sort(a.begin(), a.end(), srt);
    sort(b.begin(), b.end(), srt);
    for(int i = 1; i <= n; i++) {
        a[i] += a[i - 1];
        b[i] += b[i - 1];
    }
    //
    double res = 0;
    for(int i = 0; i <= n; i++) {
        int l = 0, r = n + 1, mid, ans;
        while(l<=r) {
            mid = (l + r) / 2;
            if(b[mid] <= a[i]) {
                ans = mid;
                l = mid + 1;
            } else r = mid - 1;
        }
        res = max(res, min(a[i], b[ans]) - i - ans);
        if(a[i] != b[ans] && ans != n) res = max(res, min(a[i], b[ans + 1]) - i - ans - 1);
        //cout << i << " " << ans << " " << res << "\n";
    }
    for(int i = 0; i <= n; i++) {
        int l = 0, r = n + 1, mid, ans;
        while(l<=r) {
            mid = (l + r) / 2;
            if(a[mid] <= b[i]) {
                ans = mid;
                l = mid + 1;
            } else r = mid - 1;
        }
        res = max(res, min(b[i], a[ans]) - i - ans);
        if(b[i] != a[ans] && ans != n) res = max(res, min(b[i], a[ans + 1]) - i - ans - 1);
        //cout << i << " " << ans << " " << res << "\n";
    }
    cout << fixed << setprecision(4) << res << "\n";
}

Compilation message

sure.cpp: In function 'int main()':
sure.cpp:49:27: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   49 |         if(b[i] != a[ans] && ans != n) res = max(res, min(b[i], a[ans + 1]) - i - ans - 1);
sure.cpp:36:27: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   36 |         if(a[i] != b[ans] && ans != n) res = max(res, min(a[i], b[ans + 1]) - i - ans - 1);
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 119 ms 3256 KB Output is correct
18 Correct 115 ms 3256 KB Output is correct
19 Correct 132 ms 3128 KB Output is correct
20 Correct 114 ms 3152 KB Output is correct
21 Correct 154 ms 3528 KB Output is correct
22 Correct 115 ms 3140 KB Output is correct
23 Correct 120 ms 3132 KB Output is correct
24 Correct 118 ms 3160 KB Output is correct
25 Correct 114 ms 3364 KB Output is correct
26 Correct 126 ms 3664 KB Output is correct