結果

問題 No.2741 Balanced Choice
ユーザー ntudantuda
提出日時 2024-04-27 00:18:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 584 ms / 2,000 ms
コード長 581 bytes
コンパイル時間 379 ms
コンパイル使用メモリ 81,960 KB
実行使用メモリ 77,696 KB
最終ジャッジ日時 2024-04-27 00:18:20
合計ジャッジ時間 6,522 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 529 ms
77,312 KB
testcase_01 AC 568 ms
77,440 KB
testcase_02 AC 584 ms
77,440 KB
testcase_03 AC 537 ms
77,416 KB
testcase_04 AC 539 ms
77,696 KB
testcase_05 AC 42 ms
53,760 KB
testcase_06 AC 47 ms
60,288 KB
testcase_07 AC 268 ms
77,552 KB
testcase_08 AC 407 ms
77,468 KB
testcase_09 AC 243 ms
77,440 KB
testcase_10 AC 295 ms
77,568 KB
testcase_11 AC 404 ms
77,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

dic = defaultdict(int)
N, W, D = map(int, input().split())
TWV = [list(map(int, input().split())) for _ in range(N)]
dp = [[-1] * (W + 1) for _ in range(2)]
dp[0][0] = 0
dp[1][0] = 0
for t, w, v in TWV:
    for i in reversed(range(W - w + 1)):
        if dp[t][i] >= 0:
            dp[t][i + w] = max(dp[t][i + w], dp[t][i] + v)
ans = 0
for i in range(W + 1):
    for j in range(W - i + 1):
        if abs(i - j) > D:
            continue
        if dp[0][i] != -1 and dp[1][j] != -1:
            ans = max(ans, dp[0][i] + dp[1][j])
print(ans)
0