結果

問題 No.2741 Balanced Choice
ユーザー kaeru82433413kaeru82433413
提出日時 2024-04-21 01:07:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 779 ms / 2,000 ms
コード長 532 bytes
コンパイル時間 596 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 78,072 KB
最終ジャッジ日時 2024-04-21 01:07:31
合計ジャッジ時間 6,575 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 502 ms
77,632 KB
testcase_01 AC 708 ms
78,072 KB
testcase_02 AC 779 ms
78,004 KB
testcase_03 AC 640 ms
77,952 KB
testcase_04 AC 767 ms
77,664 KB
testcase_05 AC 39 ms
52,480 KB
testcase_06 AC 47 ms
60,032 KB
testcase_07 AC 270 ms
77,836 KB
testcase_08 AC 402 ms
77,644 KB
testcase_09 AC 310 ms
77,568 KB
testcase_10 AC 283 ms
77,700 KB
testcase_11 AC 409 ms
77,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, W, D = map(int, input().split())
twv = [map(int, input().split()) for _ in range(N)]
wv = [[], []]
for t, w, v in twv:
    wv[t].append((w, v))

dp = [[0] + [float("-inf")]*W for _ in range(2)]
for t in range(2):
    for w, v in wv[t]:
        update = dp[t].copy()
        for i in range(W+1-w):
            update[i+w] = max(update[i+w], dp[t][i] + v)
        dp[t] = update

ans = 0
for i in range(W+1):
    for j in range(W+1):
        if i+j <= W and abs(i-j) <= D:
            ans = max(ans, dp[0][i] + dp[1][j])
print(ans)
0