Advertisement
btdat2506

Untitled

Aug 23rd, 2020
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef int ll;
  6. #define For(i, a, b) for(ll i = a; i <= b; i++)
  7.  
  8. ll n, x, h[1010], s[1010], dp[1010][100010];
  9.  
  10. void process()
  11. {
  12.     For(i, 1, n)
  13.     For(j, 1, x)
  14.     if (j >= h[i])
  15.         dp[i][j] = max(dp[i-1][j], dp[i-1][j-h[i]] + s[i]);
  16.     else
  17.         dp[i][j] = dp[i-1][j];
  18.     cout << dp[n][x] << "\n";
  19. }
  20.  
  21. void input()
  22. {
  23.     cin >> n >> x;
  24.     For(i, 1, n)
  25.     cin >> h[i];
  26.     For(i, 1, n)
  27.     cin >> s[i];
  28. }
  29.  
  30. int main()
  31. {
  32.     /* freopen("test.in", "r", stdin);
  33.     freopen("test.ok", "w", stdout); */
  34.     input();
  35.     process();
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement