結果

問題 No.2741 Balanced Choice
ユーザー Nzt3Nzt3
提出日時 2024-04-15 23:55:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 521 ms / 2,000 ms
コード長 719 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 77,568 KB
最終ジャッジ日時 2024-04-15 23:55:49
合計ジャッジ時間 4,960 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 380 ms
77,104 KB
testcase_01 AC 521 ms
77,568 KB
testcase_02 AC 505 ms
76,888 KB
testcase_03 AC 501 ms
76,844 KB
testcase_04 AC 504 ms
77,436 KB
testcase_05 AC 38 ms
52,480 KB
testcase_06 AC 42 ms
58,708 KB
testcase_07 AC 198 ms
76,880 KB
testcase_08 AC 318 ms
77,152 KB
testcase_09 AC 199 ms
77,056 KB
testcase_10 AC 219 ms
76,928 KB
testcase_11 AC 307 ms
76,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, W, D = map(int, input().split())
A0 = []
A1 = []
for _ in range(N):
    t, w, v = map(int, input().split())
    if t == 0:
        A0.append((w, v))
    else:
        A1.append((w, v))

dp0 = [-1] * (W+1)
dp0[0] = 0
for a in A0:
    for j in range(W, a[0]-1, -1):
        if dp0[j-a[0]] >= 0 and dp0[j] < dp0[j-a[0]]+a[1]:
            dp0[j] = dp0[j-a[0]]+a[1]

dp1 = [-1] * (W+1)
dp1[0] = 0
for a in A1:
    for j in range(W, a[0]-1, -1):
        if dp1[j-a[0]] >= 0 and dp1[j] < dp1[j-a[0]]+a[1]:
            dp1[j] = dp1[j-a[0]]+a[1]

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