結果

問題 No.2232 Miser's Gift
ユーザー FromBooskaFromBooska
提出日時 2023-09-12 20:44:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 351 ms / 2,000 ms
コード長 691 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 86,916 KB
実行使用メモリ 156,744 KB
最終ジャッジ日時 2023-09-12 20:45:16
合計ジャッジ時間 17,932 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,380 KB
testcase_01 AC 70 ms
71,224 KB
testcase_02 AC 75 ms
71,412 KB
testcase_03 AC 305 ms
156,644 KB
testcase_04 AC 329 ms
156,596 KB
testcase_05 AC 109 ms
85,012 KB
testcase_06 AC 69 ms
71,400 KB
testcase_07 AC 91 ms
78,492 KB
testcase_08 AC 326 ms
156,428 KB
testcase_09 AC 327 ms
156,356 KB
testcase_10 AC 312 ms
156,596 KB
testcase_11 AC 314 ms
156,428 KB
testcase_12 AC 319 ms
156,564 KB
testcase_13 AC 306 ms
156,548 KB
testcase_14 AC 304 ms
156,556 KB
testcase_15 AC 316 ms
156,704 KB
testcase_16 AC 321 ms
156,596 KB
testcase_17 AC 311 ms
156,568 KB
testcase_18 AC 308 ms
156,632 KB
testcase_19 AC 319 ms
156,744 KB
testcase_20 AC 304 ms
156,660 KB
testcase_21 AC 306 ms
156,516 KB
testcase_22 AC 307 ms
156,320 KB
testcase_23 AC 348 ms
156,424 KB
testcase_24 AC 336 ms
156,572 KB
testcase_25 AC 335 ms
156,548 KB
testcase_26 AC 351 ms
156,532 KB
testcase_27 AC 346 ms
156,700 KB
testcase_28 AC 323 ms
156,572 KB
testcase_29 AC 334 ms
156,228 KB
testcase_30 AC 331 ms
156,448 KB
testcase_31 AC 323 ms
156,664 KB
testcase_32 AC 324 ms
156,400 KB
testcase_33 AC 310 ms
156,616 KB
testcase_34 AC 306 ms
156,572 KB
testcase_35 AC 308 ms
156,624 KB
testcase_36 AC 311 ms
156,588 KB
testcase_37 AC 311 ms
156,644 KB
testcase_38 AC 90 ms
76,508 KB
testcase_39 AC 89 ms
76,444 KB
testcase_40 AC 89 ms
76,448 KB
testcase_41 AC 90 ms
76,116 KB
testcase_42 AC 90 ms
76,312 KB
testcase_43 AC 90 ms
76,424 KB
testcase_44 AC 88 ms
76,176 KB
testcase_45 AC 93 ms
76,240 KB
testcase_46 AC 91 ms
76,264 KB
testcase_47 AC 90 ms
76,344 KB
testcase_48 AC 81 ms
76,248 KB
testcase_49 AC 81 ms
75,956 KB
testcase_50 AC 84 ms
75,912 KB
testcase_51 AC 83 ms
75,864 KB
testcase_52 AC 81 ms
75,912 KB
testcase_53 AC 81 ms
75,944 KB
testcase_54 AC 82 ms
75,932 KB
testcase_55 AC 83 ms
75,836 KB
testcase_56 AC 82 ms
75,864 KB
testcase_57 AC 83 ms
75,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# ナップザック型dp
# 入力例1でX=4のときは、W=1のときのベスト値を見ると2
# W=5でのベスト値は8だから、その差よりもよければ選ばれる、よって7

N, W = map(int, input().split())
WV = []
for i in range(N):
    w, v = map(int, input().split())
    WV.append((w, v))
    
dp = [[0]*(W+1) for i in range(N+1)]

for i in range(1, N+1):
    w, v = WV[i-1]
    for j in range(W+1):
        # not using
        dp[i][j] = max(dp[i][j], dp[i-1][j])
        # using
        if j+w <= W:
            dp[i][j+w] = max(dp[i][j+w], dp[i-1][j]+v)
    #print(dp[i])
    
mx = dp[N][W]
for i in range(1, W+1):
    ans = mx - dp[N][W-i]+1
    print(ans)
    
0