Created
December 17, 2019 05:02
-
-
Save inspirit941/277f2a5028f4f1e31723be75020d9191 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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