結果

問題 No.527 ナップサック容量問題
ユーザー tktk_snsntktk_snsn
提出日時 2021-02-10 20:09:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 483 bytes
コンパイル時間 873 ms
コンパイル使用メモリ 87,144 KB
実行使用メモリ 77,396 KB
最終ジャッジ日時 2023-09-22 16:03:32
合計ジャッジ時間 6,459 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
76,712 KB
testcase_01 AC 82 ms
76,560 KB
testcase_02 AC 80 ms
76,468 KB
testcase_03 AC 85 ms
76,656 KB
testcase_04 AC 77 ms
76,624 KB
testcase_05 AC 104 ms
76,968 KB
testcase_06 AC 132 ms
77,092 KB
testcase_07 AC 121 ms
77,044 KB
testcase_08 AC 101 ms
77,108 KB
testcase_09 AC 79 ms
76,624 KB
testcase_10 AC 133 ms
77,396 KB
testcase_11 AC 117 ms
77,304 KB
testcase_12 AC 106 ms
77,128 KB
testcase_13 AC 136 ms
77,248 KB
testcase_14 AC 100 ms
77,120 KB
testcase_15 AC 108 ms
77,016 KB
testcase_16 AC 81 ms
76,568 KB
testcase_17 AC 104 ms
77,088 KB
testcase_18 AC 108 ms
77,068 KB
testcase_19 AC 85 ms
76,588 KB
testcase_20 AC 100 ms
77,300 KB
testcase_21 AC 141 ms
76,944 KB
testcase_22 AC 119 ms
76,948 KB
testcase_23 AC 137 ms
76,992 KB
testcase_24 AC 93 ms
77,272 KB
testcase_25 AC 116 ms
77,244 KB
testcase_26 AC 114 ms
77,004 KB
testcase_27 AC 115 ms
77,120 KB
testcase_28 AC 111 ms
77,044 KB
testcase_29 AC 138 ms
77,124 KB
testcase_30 AC 85 ms
77,036 KB
testcase_31 AC 104 ms
77,060 KB
testcase_32 AC 108 ms
76,944 KB
testcase_33 AC 105 ms
77,192 KB
testcase_34 AC 109 ms
77,044 KB
testcase_35 AC 113 ms
77,044 KB
testcase_36 AC 82 ms
76,468 KB
testcase_37 AC 107 ms
77,188 KB
testcase_38 AC 111 ms
77,072 KB
testcase_39 AC 109 ms
77,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
U = 10 ** 5 + 10

N = int(input())
dp = [0] * (U + 1)
Wsum = 0
for _ in range(N):
    v, w = map(int, input().split())
    Wsum += w
    for i in reversed(range(w, U + 1)):
        dp[i] = max(dp[i], dp[i - w] + v)
V = int(input())

wmin = U
wmax = 0
for i in range(1, U + 1):
    if dp[i] == V:
        wmin = min(wmin, i)
        wmax = max(wmax, i)
if wmax >= U:
    wmax = "inf"

print(wmin)
print(wmax)
0