結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 524 ms
77,696 KB
testcase_01 AC 585 ms
77,348 KB
testcase_02 AC 563 ms
77,440 KB
testcase_03 AC 548 ms
77,568 KB
testcase_04 AC 550 ms
77,824 KB
testcase_05 WA -
testcase_06 AC 50 ms
59,904 KB
testcase_07 AC 270 ms
77,440 KB
testcase_08 AC 430 ms
77,696 KB
testcase_09 AC 245 ms
77,568 KB
testcase_10 AC 290 ms
77,312 KB
testcase_11 AC 435 ms
77,440 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][i] != -1:
            ans = max(ans, dp[0][i] + dp[1][j])
print(ans)
0