結果

問題 No.527 ナップサック容量問題
ユーザー 双六双六
提出日時 2020-08-26 15:49:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 332 ms / 2,000 ms
コード長 765 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 222,464 KB
最終ジャッジ日時 2024-04-25 02:29:26
合計ジャッジ時間 7,434 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
66,560 KB
testcase_01 AC 59 ms
67,968 KB
testcase_02 AC 54 ms
64,640 KB
testcase_03 AC 56 ms
67,712 KB
testcase_04 AC 48 ms
63,232 KB
testcase_05 AC 148 ms
128,000 KB
testcase_06 AC 277 ms
199,680 KB
testcase_07 AC 222 ms
173,056 KB
testcase_08 AC 130 ms
119,296 KB
testcase_09 AC 52 ms
62,976 KB
testcase_10 AC 271 ms
202,240 KB
testcase_11 AC 187 ms
159,232 KB
testcase_12 AC 152 ms
133,504 KB
testcase_13 AC 288 ms
204,544 KB
testcase_14 AC 125 ms
115,072 KB
testcase_15 AC 173 ms
145,280 KB
testcase_16 AC 55 ms
68,224 KB
testcase_17 AC 146 ms
131,456 KB
testcase_18 AC 164 ms
141,056 KB
testcase_19 AC 63 ms
69,760 KB
testcase_20 AC 128 ms
118,016 KB
testcase_21 AC 332 ms
222,464 KB
testcase_22 AC 209 ms
169,344 KB
testcase_23 AC 295 ms
218,880 KB
testcase_24 AC 95 ms
96,128 KB
testcase_25 AC 206 ms
165,888 KB
testcase_26 AC 190 ms
155,776 KB
testcase_27 AC 195 ms
156,672 KB
testcase_28 AC 171 ms
144,128 KB
testcase_29 AC 323 ms
221,568 KB
testcase_30 AC 66 ms
76,160 KB
testcase_31 AC 143 ms
131,072 KB
testcase_32 AC 155 ms
146,816 KB
testcase_33 AC 139 ms
134,144 KB
testcase_34 AC 159 ms
150,016 KB
testcase_35 AC 190 ms
152,704 KB
testcase_36 AC 54 ms
66,432 KB
testcase_37 AC 155 ms
129,792 KB
testcase_38 AC 183 ms
147,072 KB
testcase_39 AC 167 ms
140,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	DP = [[-INF for i in range(100001)] for j in range(N + 1)]
	DP[0][0] = 0
	for i in range(N):
		v, w = getlist()
		for j in range(100001):
			if DP[i][j] != -INF:
				DP[i + 1][j] = max(DP[i][j], DP[i + 1][j]) 
				DP[i + 1][j + w] = max(DP[i + 1][j + w], DP[i][j] + v)

	V = int(input())
	m = INF
	M = INF
	for i in range(100001):
		if DP[-1][i] >= V:
			m = min(m, i)

		if DP[-1][i] > V and M == INF:
			M = i - 1

	m = max(1, m)
	if M == INF:
		M = "inf"

	print(m)
	print(M)

if __name__ == '__main__':
	main()
0