結果

問題 No.2741 Balanced Choice
ユーザー true-moleculetrue-molecule
提出日時 2024-04-20 21:48:55
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 709 bytes
コンパイル時間 1,052 ms
コンパイル使用メモリ 107,136 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 21:48:58
合計ジャッジ時間 2,038 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
6,812 KB
testcase_01 AC 52 ms
6,944 KB
testcase_02 AC 56 ms
6,940 KB
testcase_03 AC 58 ms
6,944 KB
testcase_04 AC 55 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 22 ms
6,944 KB
testcase_08 AC 39 ms
6,940 KB
testcase_09 AC 20 ms
6,940 KB
testcase_10 AC 25 ms
6,944 KB
testcase_11 AC 37 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>

int main() {
    using namespace std;
    constexpr int INF = 1'000'000'000;
    int n, max_w, d;
    cin >> n >> max_w >> d;
    vector<vector<int>> dp(2, vector<int>(max_w + 1, -INF));
    for (auto&& i : dp)
        i.at(0) = 0;
    for (int t, w, v, i = 0; i < n; ++i) {
        cin >> t >> w >> v;
        for (int j = max_w; j >= w; --j)
            dp.at(t).at(j) = max(dp.at(t).at(j), dp.at(t).at(j - w) + v);
    }
    int ans = 0;
    for (int i = 0; i <= max_w; ++i)
        for (int j = max(0, i - d); j <= min(max_w - i, i + d); ++j)
            ans = max(ans, dp.at(0).at(i) + dp.at(1).at(j));
    cout << ans << '\n';
    return 0;
}
0