Advertisement
Josif_tepe

Untitled

Mar 10th, 2023
715
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <iostream>
  2. //#include <bits/stdc++.h>
  3. #include <fstream>
  4. #include <string>
  5. #include <set>
  6. #include <cstring>
  7. #define ll long long
  8. #define ld long double
  9. #define fi first
  10. #define se second
  11. #define mp make_pair
  12. #define pb push_back
  13. #define eb emplace_back
  14. #define all(x) (x).begin(), (x).end()
  15. #define INF 1e18
  16. #define eps 0.00001
  17. #define le length
  18. #define MOD 1000000007
  19. using namespace std;
  20. ll memo[2005][2005];
  21. int prices[1005];
  22. int pages[1005];
  23. int n;
  24. int x;
  25.  
  26.  
  27.  
  28. int main() {
  29. //    ifstream cin ("input.txt");
  30.     cin >> n >> x;
  31. for(int i =0;i<n;i++){
  32.     cin >> prices[i];
  33. }
  34.  
  35. for(int i =0;i<n;i++){
  36.     cin >> pages[i];
  37. }
  38.     for(int i = 0; i < n; i++) {
  39.         for(int j = 0; j <= x; j++) {
  40.             memo[i][j] = -2e18;
  41.         }
  42.     }
  43.     memo[0][x] = 0;
  44.     for(int i  =0; i < n; i++) {
  45.         for(int j = x; j >= 0; j--) {
  46.             memo[i + 1][j] = max(memo[i + 1][j], memo[i][j]);
  47.             if(j - prices[i] >= 0) {
  48.                 memo[i + 1][j - prices[i]] = max(memo[i + 1][j - prices[i]], memo[i][j] + pages[i]);
  49.             }
  50.         }
  51.     }
  52.     ll result = 0;
  53.     for(int i = 0; i <= x; i++) {
  54.         result = max(result, memo[n][i]);
  55.     }
  56.     cout << result << endl;
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement