結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
76,368 KB
testcase_01 AC 78 ms
76,520 KB
testcase_02 AC 77 ms
76,424 KB
testcase_03 AC 79 ms
76,500 KB
testcase_04 AC 76 ms
76,356 KB
testcase_05 AC 105 ms
77,016 KB
testcase_06 AC 138 ms
77,032 KB
testcase_07 AC 124 ms
77,312 KB
testcase_08 AC 102 ms
77,000 KB
testcase_09 AC 77 ms
76,784 KB
testcase_10 AC 136 ms
76,876 KB
testcase_11 AC 114 ms
77,020 KB
testcase_12 AC 105 ms
77,116 KB
testcase_13 AC 140 ms
77,508 KB
testcase_14 AC 98 ms
77,004 KB
testcase_15 AC 111 ms
77,000 KB
testcase_16 AC 81 ms
76,428 KB
testcase_17 AC 103 ms
77,020 KB
testcase_18 AC 108 ms
77,008 KB
testcase_19 AC 78 ms
76,724 KB
testcase_20 AC 97 ms
77,212 KB
testcase_21 AC 147 ms
77,116 KB
testcase_22 AC 121 ms
77,088 KB
testcase_23 AC 143 ms
77,004 KB
testcase_24 AC 88 ms
76,996 KB
testcase_25 AC 119 ms
77,232 KB
testcase_26 AC 116 ms
77,132 KB
testcase_27 AC 115 ms
77,012 KB
testcase_28 AC 110 ms
77,280 KB
testcase_29 AC 148 ms
77,252 KB
testcase_30 AC 82 ms
77,072 KB
testcase_31 AC 100 ms
77,012 KB
testcase_32 AC 108 ms
76,872 KB
testcase_33 AC 105 ms
77,268 KB
testcase_34 AC 108 ms
77,248 KB
testcase_35 AC 114 ms
77,148 KB
testcase_36 AC 80 ms
76,368 KB
testcase_37 AC 106 ms
77,548 KB
testcase_38 AC 114 ms
77,292 KB
testcase_39 AC 108 ms
77,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

for i in range(1,100010):
    DP[i]=max(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