Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- ios::sync_with_stdio(0);
- cin.tie(0);
- int n, x; cin >> n >> x;
- vector<int> H(n), S(n), K(n);
- for(int i = 0; i < n; ++i) cin >> H[i];
- for(int i = 0; i < n; ++i) cin >> S[i];
- for(int i = 0; i < n; ++i) cin >> K[i];
- vector<vector<int>> dp(n+1, vector<int>(x+1, 0));
- //dp[i][j]: max number of pages up to pos i with availbale x money
- for(int i = 1; i <= n; ++i){
- for(int j = 1; j <= x; ++j){
- for(int q = 0; q <= K[i-1] and j - q*H[i-1] >= 0; ++q){
- dp[i][j] = max(dp[i][j], q*S[i-1] + dp[i-1][j-q*H[i-1]]);
- }
- }
- }
- cout << dp[n][x] << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement