답안 #987061

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
987061 2024-05-21T19:08:03 Z aaaaaarroz Sure Bet (CEOI17_sure) C++17
100 / 100
135 ms 3732 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:31: 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:31: 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 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 500 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 436 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 500 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 436 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 116 ms 3140 KB Output is correct
18 Correct 117 ms 3144 KB Output is correct
19 Correct 117 ms 3156 KB Output is correct
20 Correct 135 ms 3520 KB Output is correct
21 Correct 130 ms 3512 KB Output is correct
22 Correct 116 ms 3260 KB Output is correct
23 Correct 115 ms 3152 KB Output is correct
24 Correct 116 ms 3360 KB Output is correct
25 Correct 116 ms 3152 KB Output is correct
26 Correct 126 ms 3732 KB Output is correct