結果

問題 No.527 ナップサック容量問題
ユーザー 👑 H20H20
提出日時 2022-02-14 22:03:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 508 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 86,720 KB
実行使用メモリ 77,224 KB
最終ジャッジ日時 2023-09-11 16:48:53
合計ジャッジ時間 5,345 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
76,500 KB
testcase_01 AC 76 ms
76,704 KB
testcase_02 AC 78 ms
76,384 KB
testcase_03 AC 79 ms
76,500 KB
testcase_04 AC 76 ms
76,220 KB
testcase_05 AC 90 ms
76,980 KB
testcase_06 AC 111 ms
77,108 KB
testcase_07 AC 101 ms
77,004 KB
testcase_08 AC 85 ms
76,364 KB
testcase_09 AC 72 ms
76,564 KB
testcase_10 AC 112 ms
76,988 KB
testcase_11 AC 97 ms
76,940 KB
testcase_12 AC 90 ms
77,220 KB
testcase_13 AC 117 ms
77,080 KB
testcase_14 AC 85 ms
76,548 KB
testcase_15 AC 93 ms
76,988 KB
testcase_16 AC 77 ms
76,612 KB
testcase_17 AC 88 ms
77,172 KB
testcase_18 AC 88 ms
77,224 KB
testcase_19 AC 77 ms
76,824 KB
testcase_20 AC 87 ms
76,636 KB
testcase_21 AC 121 ms
77,004 KB
testcase_22 AC 97 ms
76,992 KB
testcase_23 AC 114 ms
76,980 KB
testcase_24 AC 77 ms
76,368 KB
testcase_25 AC 95 ms
76,992 KB
testcase_26 AC 97 ms
76,844 KB
testcase_27 AC 98 ms
76,988 KB
testcase_28 AC 92 ms
77,052 KB
testcase_29 AC 119 ms
77,100 KB
testcase_30 AC 73 ms
76,668 KB
testcase_31 AC 85 ms
76,944 KB
testcase_32 AC 87 ms
76,996 KB
testcase_33 AC 86 ms
76,948 KB
testcase_34 AC 88 ms
77,116 KB
testcase_35 AC 95 ms
76,836 KB
testcase_36 AC 77 ms
76,600 KB
testcase_37 AC 93 ms
77,132 KB
testcase_38 AC 92 ms
77,056 KB
testcase_39 AC 92 ms
77,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
VW = [list(map(int, input().split())) for _ in range(N)]
V = int(input())
DP = [0]*(100010)
j=1
for v,w in VW:
    for i in reversed(range(1000*j+10)):
        if DP[i]>0:
            DP[i+w]=max(DP[i+w],DP[i]+v)
    DP[w]=max(DP[w],v)
    j+=1

for i in range(1,100010):
    if DP[i]<DP[i-1]:
        DP[i]=DP[i-1]

mi=0
ma=0
for i in range(100010):
    if DP[i]==V and mi==0:
        mi=i
    if DP[i]==V:
        ma=i


print(max(mi,1))
if ma==100009:
    print('inf')
else:
    print(ma)
0