結果

問題 No.527 ナップサック容量問題
ユーザー AEnAEn
提出日時 2022-08-24 16:49:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 290 ms / 2,000 ms
コード長 595 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 82,224 KB
実行使用メモリ 143,864 KB
最終ジャッジ日時 2024-04-20 06:19:51
合計ジャッジ時間 7,275 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
65,632 KB
testcase_01 AC 50 ms
65,976 KB
testcase_02 AC 44 ms
62,928 KB
testcase_03 AC 54 ms
67,044 KB
testcase_04 AC 38 ms
61,408 KB
testcase_05 AC 127 ms
97,024 KB
testcase_06 AC 231 ms
132,992 KB
testcase_07 AC 246 ms
119,784 KB
testcase_08 AC 145 ms
91,692 KB
testcase_09 AC 44 ms
60,604 KB
testcase_10 AC 265 ms
133,060 KB
testcase_11 AC 167 ms
113,156 KB
testcase_12 AC 130 ms
99,524 KB
testcase_13 AC 223 ms
134,188 KB
testcase_14 AC 108 ms
90,600 KB
testcase_15 AC 161 ms
104,912 KB
testcase_16 AC 61 ms
66,632 KB
testcase_17 AC 141 ms
97,356 KB
testcase_18 AC 149 ms
102,032 KB
testcase_19 AC 65 ms
68,980 KB
testcase_20 AC 107 ms
91,340 KB
testcase_21 AC 241 ms
143,864 KB
testcase_22 AC 174 ms
117,444 KB
testcase_23 AC 234 ms
142,824 KB
testcase_24 AC 82 ms
80,688 KB
testcase_25 AC 169 ms
115,376 KB
testcase_26 AC 176 ms
110,224 KB
testcase_27 AC 218 ms
110,332 KB
testcase_28 AC 164 ms
103,916 KB
testcase_29 AC 290 ms
143,676 KB
testcase_30 AC 61 ms
68,216 KB
testcase_31 AC 132 ms
96,464 KB
testcase_32 AC 145 ms
104,888 KB
testcase_33 AC 129 ms
98,160 KB
testcase_34 AC 147 ms
106,044 KB
testcase_35 AC 171 ms
107,416 KB
testcase_36 AC 56 ms
65,016 KB
testcase_37 AC 161 ms
98,552 KB
testcase_38 AC 165 ms
104,460 KB
testcase_39 AC 145 ms
103,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
item = [list(map(int, input().split())) for _ in range(N)]
V = int(input())
dp = [[0]*(10**5+1) for _ in range(N+1)]
sm_v, sm_w = 0, 0
for i in range(1, N+1):
    v, w = item[i-1]
    sm_v += v
    sm_w += w
    for j in range(10**5+1):
        if j>=w:
            dp[i][j] = max(dp[i-1][j-w]+v, dp[i][j])
        dp[i][j] = max(dp[i][j], dp[i-1][j])

for i in range(1,10**5+1):
    if dp[-1][i] == V:
        print(i)
        break
if dp[-1][sm_w] == V:
    print('inf')
else:
    for i in range(10**5, 0, -1):
        if dp[-1][i] == V:
            print(i)
            break
0