Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- N, M = map(int, input().split())
- weight = [0] + [int(i) for i in input().split()]
- cost =[0] + [int(i) for i in input().split()]
- dp = [[0] * (M+1) for x in range(N+1)]
- for n in range(1, N+1):
- for m in range(M+1):
- dp[n][m] = dp[n-1][m]
- if (m >= weight[n] and dp[n-1][m-weight[n]] + cost[n] > dp[n][m]):
- dp[n][m] = dp[n-1][m-weight[n]] + cost[n]
- print(dp[N][M])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement