Advertisement
ashibh

Untitled

Apr 19th, 2024
636
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | Source Code | 0 0
  1. //                                                     (┬┬﹏┬┬)
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define lli long long int
  5.  
  6. int main()
  7. {
  8.     ios_base::sync_with_stdio(0);
  9.     cin.tie(0);
  10.     cout.tie(0);
  11. #ifndef ONLINE_JUDGE
  12.     freopen("input.txt", "r", stdin);
  13.     freopen("output.txt", "w", stdout);
  14. #endif
  15.  
  16.  
  17.     int n, mny;
  18.     cin >> n >> mny;
  19.     vector<int>pr(n), pg(n);
  20.  
  21.     for (int i = 0; i < n; ++i)
  22.         cin >> pr[i];
  23.  
  24.     for (int i = 0; i < n; ++i)
  25.         cin >> pg[i];
  26.  
  27.     vector<vector<int>> dp(n + 1, vector<int>(mny + 1, 0));
  28.  
  29.  
  30.     for (int i = 1; i <= n; ++i)
  31.     {
  32.         for (int j = 0; j <= mny; ++j)
  33.         {
  34.             dp[i][j] = dp[i - 1][j];
  35.             int lf = j - pr[i - 1];
  36.             if (lf >= 0 ) {
  37.                 dp[i][j] = max(dp[i][j], pg[i - 1] + dp[i - 1][lf]);
  38.             }
  39.         }
  40.     }
  41.  
  42.     cout << dp[n][mny];
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement