Skip to content

Instantly share code, notes, and snippets.

@inspirit941
Created December 17, 2019 05:02
Show Gist options
  • Save inspirit941/277f2a5028f4f1e31723be75020d9191 to your computer and use it in GitHub Desktop.
Save inspirit941/277f2a5028f4f1e31723be75020d9191 to your computer and use it in GitHub Desktop.
import sys
N, K = map(int, sys.stdin.readline().split())
result = [[0 for _ in range(K+1)] for _ in range(N)]
for i in range(N):
weight, value = map(int, sys.stdin.readline().split())
for idx in range(1, K+1):
if idx >= weight:
result[i][idx] = max(result[i-1][idx], result[i-1][idx - weight] + value)
else:
result[i][idx] = result[i-1][idx]
print(max(result[-1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment