結果

問題 No.527 ナップサック容量問題
ユーザー brthyyjp
提出日時 2022-03-02 13:24:02
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 453 bytes
コンパイル時間 331 ms
コンパイル使用メモリ 82,224 KB
実行使用メモリ 75,708 KB
最終ジャッジ日時 2024-07-16 06:42:34
合計ジャッジ時間 3,696 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
V = []
W = []
for i in range(n):
    v, w = map(int, input().split())
    V.append(v)
    W.append(w)
u = int(input())
if u == 0:
    print(1)
    print(min(W)-1)
    exit()
INF = 10**18
dp = [INF]*(u+2)
dp[0] = 0
for v, w in zip(V, W):
    for i in reversed(range(u+2)):
        if i+v <= u+1:
            dp[i+v] = min(dp[i+v], dp[i]+w)
if dp[u+1] != INF:
    print(dp[u])
    print(dp[u+1]-1)
else:
    print(dp[u])
    print('inf')
0