Advertisement
FlyingElephant

Untitled

Apr 16th, 2023
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | Software | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){  
  5.     ios::sync_with_stdio(0);
  6.     cin.tie(0);
  7.    
  8.     int n, x; cin >> n >> x;
  9.     vector<int> H(n), S(n), K(n);
  10.     for(int i = 0; i < n; ++i) cin >> H[i];
  11.     for(int i = 0; i < n; ++i) cin >> S[i];
  12.     for(int i = 0; i < n; ++i) cin >> K[i];
  13.    
  14.     vector<vector<int>> dp(n+1, vector<int>(x+1, 0));
  15.     //dp[i][j]: max number of pages up to pos i with availbale x money
  16.     for(int i = 1; i <= n; ++i){
  17.         for(int j = 1; j <= x; ++j){
  18.             for(int q = 0; q <= K[i-1] and j - q*H[i-1] >= 0; ++q){
  19.                 dp[i][j] = max(dp[i][j], q*S[i-1] + dp[i-1][j-q*H[i-1]]);
  20.             }
  21.         }
  22.     }
  23.     cout << dp[n][x] << "\n";
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement