提出 #62063724


ソースコード 拡げる

#include<bits/stdc++.h>

using namespace std;

int main() {
    cin.tie(nullptr) -> sync_with_stdio(false);
    int n, w;
    cin >> n >> w;
    array<vector<int>, 3> f;
    for(int i = 0; i < 3; i++) {
        f[i].resize(w + 1, 0);
    }
    for(int i = 0, v, a, c; i < n; i++) {
        cin >> v >> a >> c;
        v--;
        for(int j = w; j >= c; j--) {
            f[v][j] = max(f[v][j - c] + a, f[v][j]);
        }
    }
    cerr << "OK\n";

    auto check = [&](int x) -> bool {
        int res = 0;
        for(int i = 0; i < 3; i++) {
            int add = (int)(lower_bound(f[i].begin(), f[i].end(), x) - f[i].begin());
            if(add == w + 1) {
                return 0;
            }
            res += add;
        }
        return res <= w;
    };

    int lo = 0, hi = 1e9, ans = -1;
    while(lo <= hi) {
        int mid = (lo + hi) >> 1;
        if(check(mid)) {
            lo = mid + 1, ans = mid;
        } else {
            hi = mid - 1;
        }
    }

    cout << ans << '\n';

    return 0;
}

提出情報

提出日時
問題 E - Vitamin Balance
ユーザ dengstar
言語 C++ 20 (gcc 12.2)
得点 450
コード長 1072 Byte
結果 AC
実行時間 31 ms
メモリ 3668 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 450 / 450
結果
AC × 2
AC × 58
セット名 テストケース
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, random_38.txt, random_39.txt, random_40.txt, random_41.txt, random_42.txt, random_43.txt, random_44.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 1 ms 3524 KiB
example_01.txt AC 1 ms 3440 KiB
hand_00.txt AC 1 ms 3352 KiB
hand_01.txt AC 18 ms 3516 KiB
hand_02.txt AC 1 ms 3596 KiB
hand_03.txt AC 16 ms 3504 KiB
hand_04.txt AC 1 ms 3448 KiB
hand_05.txt AC 1 ms 3416 KiB
hand_06.txt AC 31 ms 3552 KiB
hand_07.txt AC 2 ms 3476 KiB
hand_08.txt AC 1 ms 3456 KiB
hand_09.txt AC 1 ms 3416 KiB
hand_10.txt AC 31 ms 3456 KiB
random_00.txt AC 1 ms 3532 KiB
random_01.txt AC 1 ms 3540 KiB
random_02.txt AC 1 ms 3532 KiB
random_03.txt AC 1 ms 3388 KiB
random_04.txt AC 1 ms 3588 KiB
random_05.txt AC 1 ms 3536 KiB
random_06.txt AC 2 ms 3448 KiB
random_07.txt AC 2 ms 3668 KiB
random_08.txt AC 1 ms 3544 KiB
random_09.txt AC 3 ms 3504 KiB
random_10.txt AC 3 ms 3548 KiB
random_11.txt AC 3 ms 3476 KiB
random_12.txt AC 10 ms 3516 KiB
random_13.txt AC 10 ms 3500 KiB
random_14.txt AC 9 ms 3664 KiB
random_15.txt AC 1 ms 3548 KiB
random_16.txt AC 1 ms 3476 KiB
random_17.txt AC 1 ms 3668 KiB
random_18.txt AC 1 ms 3496 KiB
random_19.txt AC 2 ms 3580 KiB
random_20.txt AC 1 ms 3536 KiB
random_21.txt AC 2 ms 3536 KiB
random_22.txt AC 2 ms 3480 KiB
random_23.txt AC 2 ms 3560 KiB
random_24.txt AC 4 ms 3452 KiB
random_25.txt AC 3 ms 3484 KiB
random_26.txt AC 7 ms 3472 KiB
random_27.txt AC 16 ms 3496 KiB
random_28.txt AC 18 ms 3460 KiB
random_29.txt AC 8 ms 3456 KiB
random_30.txt AC 1 ms 3528 KiB
random_31.txt AC 1 ms 3504 KiB
random_32.txt AC 1 ms 3380 KiB
random_33.txt AC 1 ms 3380 KiB
random_34.txt AC 1 ms 3492 KiB
random_35.txt AC 1 ms 3416 KiB
random_36.txt AC 1 ms 3444 KiB
random_37.txt AC 2 ms 3460 KiB
random_38.txt AC 2 ms 3476 KiB
random_39.txt AC 2 ms 3544 KiB
random_40.txt AC 3 ms 3520 KiB
random_41.txt AC 2 ms 3512 KiB
random_42.txt AC 19 ms 3384 KiB
random_43.txt AC 26 ms 3508 KiB
random_44.txt AC 3 ms 3616 KiB