結果

問題 No.2232 Miser's Gift
ユーザー napiernapier
提出日時 2023-03-03 21:43:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 719 ms / 2,000 ms
コード長 609 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 81,612 KB
実行使用メモリ 236,088 KB
最終ジャッジ日時 2023-10-18 01:40:39
合計ジャッジ時間 20,834 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,368 KB
testcase_01 AC 38 ms
53,368 KB
testcase_02 AC 38 ms
53,368 KB
testcase_03 AC 429 ms
235,504 KB
testcase_04 AC 491 ms
235,552 KB
testcase_05 AC 100 ms
83,736 KB
testcase_06 AC 37 ms
53,368 KB
testcase_07 AC 72 ms
79,788 KB
testcase_08 AC 412 ms
235,820 KB
testcase_09 AC 409 ms
235,820 KB
testcase_10 AC 414 ms
235,820 KB
testcase_11 AC 414 ms
235,820 KB
testcase_12 AC 413 ms
235,820 KB
testcase_13 AC 422 ms
236,084 KB
testcase_14 AC 425 ms
236,084 KB
testcase_15 AC 427 ms
235,820 KB
testcase_16 AC 423 ms
236,084 KB
testcase_17 AC 425 ms
236,084 KB
testcase_18 AC 425 ms
235,820 KB
testcase_19 AC 425 ms
235,820 KB
testcase_20 AC 426 ms
236,084 KB
testcase_21 AC 425 ms
235,820 KB
testcase_22 AC 424 ms
235,820 KB
testcase_23 AC 632 ms
235,436 KB
testcase_24 AC 638 ms
235,404 KB
testcase_25 AC 719 ms
235,548 KB
testcase_26 AC 632 ms
236,032 KB
testcase_27 AC 634 ms
235,548 KB
testcase_28 AC 513 ms
235,436 KB
testcase_29 AC 507 ms
235,436 KB
testcase_30 AC 500 ms
235,436 KB
testcase_31 AC 510 ms
235,436 KB
testcase_32 AC 520 ms
235,436 KB
testcase_33 AC 442 ms
235,960 KB
testcase_34 AC 440 ms
236,088 KB
testcase_35 AC 441 ms
236,088 KB
testcase_36 AC 432 ms
235,824 KB
testcase_37 AC 437 ms
235,824 KB
testcase_38 AC 73 ms
72,308 KB
testcase_39 AC 74 ms
72,308 KB
testcase_40 AC 73 ms
72,308 KB
testcase_41 AC 77 ms
73,220 KB
testcase_42 AC 75 ms
73,228 KB
testcase_43 AC 75 ms
73,220 KB
testcase_44 AC 76 ms
73,232 KB
testcase_45 AC 77 ms
73,228 KB
testcase_46 AC 75 ms
72,836 KB
testcase_47 AC 73 ms
72,308 KB
testcase_48 AC 63 ms
68,060 KB
testcase_49 AC 63 ms
68,068 KB
testcase_50 AC 62 ms
68,056 KB
testcase_51 AC 62 ms
68,048 KB
testcase_52 AC 64 ms
68,056 KB
testcase_53 AC 61 ms
68,048 KB
testcase_54 AC 62 ms
68,060 KB
testcase_55 AC 62 ms
68,068 KB
testcase_56 AC 60 ms
68,032 KB
testcase_57 AC 62 ms
68,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, W = map(int, input().split())

inf = float('inf')

w, v = [], []
for _ in range(N):
    ww, vv = map(int, input().split())
    w.append(ww)
    v.append(vv)

# dp[i][j] [0:i]まで見て合計がjの時の価値の総和の最大値
dp = [[-inf]*(W+1) for _ in range(N+1)]
dp[0][0] = 0

for i in range(N):
    for j in range(W+1):
        if j+w[i] <= W:
            dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]], dp[i][j] + v[i])
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])

dp = dp[N]
m = [-inf]*(W+2)
for i in range(W+1):
    m[i+1] = max(m[i], dp[i])

for x in range(1, W+1):
    print(m[-1] - m[W-x+1] + 1)
0