結果

問題 No.2232 Miser's Gift
ユーザー FromBooskaFromBooska
提出日時 2023-03-04 14:38:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 340 ms / 2,000 ms
コード長 947 bytes
コンパイル時間 595 ms
コンパイル使用メモリ 81,704 KB
実行使用メモリ 155,804 KB
最終ジャッジ日時 2023-10-18 04:34:10
合計ジャッジ時間 13,141 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,360 KB
testcase_01 AC 41 ms
53,360 KB
testcase_02 AC 39 ms
53,360 KB
testcase_03 AC 263 ms
155,780 KB
testcase_04 AC 265 ms
155,364 KB
testcase_05 AC 74 ms
73,556 KB
testcase_06 AC 39 ms
53,360 KB
testcase_07 AC 68 ms
77,364 KB
testcase_08 AC 275 ms
155,364 KB
testcase_09 AC 277 ms
155,364 KB
testcase_10 AC 272 ms
155,364 KB
testcase_11 AC 332 ms
155,360 KB
testcase_12 AC 278 ms
155,364 KB
testcase_13 AC 260 ms
155,764 KB
testcase_14 AC 258 ms
155,756 KB
testcase_15 AC 260 ms
155,768 KB
testcase_16 AC 255 ms
155,760 KB
testcase_17 AC 255 ms
155,756 KB
testcase_18 AC 258 ms
155,784 KB
testcase_19 AC 257 ms
155,760 KB
testcase_20 AC 256 ms
155,760 KB
testcase_21 AC 263 ms
155,804 KB
testcase_22 AC 256 ms
155,792 KB
testcase_23 AC 337 ms
155,364 KB
testcase_24 AC 340 ms
155,364 KB
testcase_25 AC 340 ms
155,364 KB
testcase_26 AC 338 ms
155,364 KB
testcase_27 AC 333 ms
155,364 KB
testcase_28 AC 273 ms
155,364 KB
testcase_29 AC 273 ms
155,364 KB
testcase_30 AC 276 ms
155,364 KB
testcase_31 AC 312 ms
155,364 KB
testcase_32 AC 311 ms
155,364 KB
testcase_33 AC 260 ms
155,804 KB
testcase_34 AC 259 ms
155,780 KB
testcase_35 AC 267 ms
155,792 KB
testcase_36 AC 262 ms
155,760 KB
testcase_37 AC 260 ms
155,776 KB
testcase_38 AC 58 ms
65,980 KB
testcase_39 AC 58 ms
65,980 KB
testcase_40 AC 58 ms
65,980 KB
testcase_41 AC 58 ms
65,980 KB
testcase_42 AC 58 ms
65,984 KB
testcase_43 AC 59 ms
65,980 KB
testcase_44 AC 58 ms
65,984 KB
testcase_45 AC 58 ms
65,984 KB
testcase_46 AC 59 ms
65,984 KB
testcase_47 AC 58 ms
65,984 KB
testcase_48 AC 51 ms
61,688 KB
testcase_49 AC 51 ms
61,688 KB
testcase_50 AC 52 ms
61,688 KB
testcase_51 AC 51 ms
61,688 KB
testcase_52 AC 52 ms
61,688 KB
testcase_53 AC 51 ms
61,688 KB
testcase_54 AC 51 ms
61,688 KB
testcase_55 AC 51 ms
61,688 KB
testcase_56 AC 50 ms
61,688 KB
testcase_57 AC 51 ms
61,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# ナップザック問題の変形バージョン
# ナップザックは1度だけやる
# 入力例1でたとえばx=3ならW-3=2を見ると、ナップザックの最大価値3で現在のナップザックW最大価値8
# これでx=3の価値が5なら差がつかない、Wでの値が1を上回れば差がつくので、価値は6とする

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

for i in range(N):
    for j in range(W+1):
        # use i
        if j - weight[i] >= 0:
            dp[i][j] = max(dp[i-1][j - weight[i]] + value[i], dp[i-1][j])
        else:
            # no use set i
            dp[i][j] = dp[i-1][j]

#print(dp[N-1])

for x in range(1, W+1):
    current_value = dp[N-1][W-x]
    current_diff = dp[N-1][W] - current_value
    ans = current_diff+1
    print(ans)
0