結果

問題 No.2741 Balanced Choice
ユーザー Nzt3Nzt3
提出日時 2024-04-15 23:57:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 479 ms / 2,000 ms
コード長 653 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 82,816 KB
実行使用メモリ 77,272 KB
最終ジャッジ日時 2024-04-15 23:57:56
合計ジャッジ時間 4,271 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 294 ms
76,988 KB
testcase_01 AC 447 ms
77,272 KB
testcase_02 AC 440 ms
77,056 KB
testcase_03 AC 479 ms
76,896 KB
testcase_04 AC 417 ms
77,056 KB
testcase_05 AC 40 ms
52,224 KB
testcase_06 AC 45 ms
58,752 KB
testcase_07 AC 194 ms
76,800 KB
testcase_08 AC 260 ms
76,800 KB
testcase_09 AC 184 ms
76,928 KB
testcase_10 AC 199 ms
76,948 KB
testcase_11 AC 259 ms
77,184 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 = [-10**8] * (W+1)
dp0[0] = 0
for a in A0:
    for j in range(W, a[0]-1, -1):
        if dp0[j] < dp0[j-a[0]]+a[1]:
            dp0[j] = dp0[j-a[0]]+a[1]

dp1 = [-10**8] * (W+1)
dp1[0] = 0
for a in A1:
    for j in range(W, a[0]-1, -1):
        if 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:
            ans = max(ans, dp0[i]+dp1[j])
print(ans)
0