CSES - Shared codeLink to this code:
https://cses.fi/paste/1c4afcf48c0400b071e0f8/
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 i in range(n): # for each item
for j in range(x, weights[i] - 1, -1): # iterate downwards
dp[j] = max(dp[j], dp[j - weights[i]] + vals[i])
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()