Advertisement
Egor_1425

Untitled

Apr 22nd, 2024
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. N, M = map(int, input().split())
  2. weight = [0] + [int(i) for i in input().split()]
  3. cost =[0] + [int(i) for i in input().split()]
  4. dp = [[0] * (M+1) for x in range(N+1)]
  5.  
  6. for n in range(1, N+1):
  7.     for m in range(M+1):
  8.         dp[n][m] = dp[n-1][m]
  9.         if (m >= weight[n] and dp[n-1][m-weight[n]] + cost[n] > dp[n][m]):
  10.             dp[n][m] =  dp[n-1][m-weight[n]] + cost[n]
  11.  
  12. print(dp[N][M])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement