CSES - Shared codeLink to this code:
https://cses.fi/paste/85c4f40b683a6eec71e10d/
import sys
input = sys.stdin.readline
def solve(n, x, weights, vals): # knapsack
dp = [0] * (x + 1) # max val for weight limit of i
for weight, value in zip(weights, vals):
for j in range(x, weight - 1, -1):
dp[j] = max(dp[j], dp[j - weight] + value)
print(dp[x])
def main():
n, x = list(map(int, input().split()))
weights = list(map(int, input().split()))
vals = list(map(int, input().split()))
solve(n, x, weights, vals)
main()