結果

問題 No.527 ナップサック容量問題
ユーザー neterukunneterukun
提出日時 2019-06-10 05:45:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 168 ms / 2,000 ms
コード長 733 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 100,480 KB
最終ジャッジ日時 2024-04-15 20:13:23
合計ジャッジ時間 4,584 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,352 KB
testcase_01 AC 51 ms
59,904 KB
testcase_02 AC 39 ms
52,224 KB
testcase_03 AC 53 ms
61,952 KB
testcase_04 AC 39 ms
52,096 KB
testcase_05 AC 72 ms
68,608 KB
testcase_06 AC 143 ms
92,928 KB
testcase_07 AC 113 ms
81,664 KB
testcase_08 AC 67 ms
66,048 KB
testcase_09 AC 40 ms
51,712 KB
testcase_10 AC 142 ms
91,776 KB
testcase_11 AC 91 ms
73,856 KB
testcase_12 AC 73 ms
68,992 KB
testcase_13 AC 150 ms
94,976 KB
testcase_14 AC 69 ms
67,200 KB
testcase_15 AC 88 ms
73,216 KB
testcase_16 AC 54 ms
61,440 KB
testcase_17 AC 73 ms
69,120 KB
testcase_18 AC 80 ms
71,296 KB
testcase_19 AC 55 ms
62,208 KB
testcase_20 AC 65 ms
65,792 KB
testcase_21 AC 168 ms
99,200 KB
testcase_22 AC 112 ms
81,920 KB
testcase_23 AC 150 ms
93,312 KB
testcase_24 AC 60 ms
63,232 KB
testcase_25 AC 97 ms
77,568 KB
testcase_26 AC 90 ms
74,752 KB
testcase_27 AC 96 ms
76,160 KB
testcase_28 AC 88 ms
73,344 KB
testcase_29 AC 166 ms
100,480 KB
testcase_30 AC 39 ms
52,224 KB
testcase_31 AC 50 ms
60,672 KB
testcase_32 AC 53 ms
61,440 KB
testcase_33 AC 49 ms
60,800 KB
testcase_34 AC 49 ms
60,416 KB
testcase_35 AC 93 ms
74,880 KB
testcase_36 AC 52 ms
61,056 KB
testcase_37 AC 77 ms
69,504 KB
testcase_38 AC 84 ms
72,576 KB
testcase_39 AC 81 ms
71,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
info = [list(map(int, input().split())) for i in range(n)]
v = int(input())

sum_w = 0
for i in range(n):
    sum_w += info[i][1]

# dp[i][j] := i番目の荷物を入れたときの、重さj以下で実現できる最大価値
dp = [[0]*(sum_w+1) for i in range(n+1)]

for i in range(n):
    for j in range(sum_w+1):
        if j - info[i][1] < 0:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-info[i][1]] + info[i][0])

flag = False
min_w = 0
max_w = "inf"
for j in range(sum_w+1):
    if dp[n][j] == v and not flag:
        min_w = j
        flag = True
    elif dp[n][j] != v and flag:
        max_w = j - 1
        flag = False
print(max(min_w, 1))
print(max_w)
0