結果

問題 No.527 ナップサック容量問題
ユーザー irumo8202irumo8202
提出日時 2022-01-28 11:25:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 472 bytes
コンパイル時間 349 ms
コンパイル使用メモリ 87,220 KB
実行使用メモリ 77,928 KB
最終ジャッジ日時 2023-08-27 22:24:44
合計ジャッジ時間 7,201 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
76,252 KB
testcase_01 AC 82 ms
76,088 KB
testcase_02 AC 84 ms
76,424 KB
testcase_03 AC 81 ms
76,512 KB
testcase_04 AC 73 ms
71,472 KB
testcase_05 AC 105 ms
77,124 KB
testcase_06 AC 153 ms
77,628 KB
testcase_07 AC 129 ms
77,340 KB
testcase_08 AC 101 ms
76,800 KB
testcase_09 AC 75 ms
71,276 KB
testcase_10 AC 154 ms
77,788 KB
testcase_11 AC 120 ms
77,328 KB
testcase_12 AC 107 ms
77,152 KB
testcase_13 AC 158 ms
77,756 KB
testcase_14 AC 98 ms
76,800 KB
testcase_15 AC 114 ms
77,160 KB
testcase_16 AC 81 ms
76,244 KB
testcase_17 AC 105 ms
76,832 KB
testcase_18 AC 110 ms
76,924 KB
testcase_19 AC 83 ms
76,248 KB
testcase_20 AC 99 ms
76,780 KB
testcase_21 AC 171 ms
77,928 KB
testcase_22 AC 128 ms
77,212 KB
testcase_23 AC 165 ms
77,812 KB
testcase_24 AC 91 ms
76,472 KB
testcase_25 AC 121 ms
77,296 KB
testcase_26 AC 119 ms
77,180 KB
testcase_27 AC 118 ms
77,096 KB
testcase_28 AC 112 ms
77,032 KB
testcase_29 AC 163 ms
77,812 KB
testcase_30 AC 82 ms
76,356 KB
testcase_31 AC 96 ms
77,108 KB
testcase_32 AC 101 ms
77,076 KB
testcase_33 AC 97 ms
76,832 KB
testcase_34 AC 103 ms
76,996 KB
testcase_35 AC 115 ms
77,220 KB
testcase_36 AC 81 ms
76,428 KB
testcase_37 AC 106 ms
76,852 KB
testcase_38 AC 112 ms
77,224 KB
testcase_39 AC 108 ms
77,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from cmath import inf

N = int(input())

dp = [-inf] * (1000 * N + 1)
dp[0] = 0

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

for i in range(1, 1000 * N + 1):
    dp[i] = max(dp[i], dp[i - 1])

V = int(input())
mi, mx = inf, -1

for i in range(1, 1000 * N + 1):
    if dp[i] == V:
        mi = min(mi, i)
        mx = max(mx, i)

print(mi)
print(mx if mx != 1000 * N else inf)
0