Advertisement
midnight_sun

Untitled

Nov 15th, 2022
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #define MAX 200000000
  3. #define MAXN 101
  4. #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
  5. using namespace std;
  6. int a[MAXN], c[MAXN], dp[MAXN][10001];
  7. int main() {
  8.     fastio;
  9.     int n, m;
  10.     cin >> n >> m;
  11.     for (int i = 0; i < n; i++) cin >> a[i];
  12.     for (int i = 0; i < n; i++) cin >> c[i];
  13.     int ans = MAX;
  14.     dp[0][c[0]] = a[0];
  15.     for (int i = 1; i <= n; i++) {
  16.         for (int j = 0; j <= 10000; j++) {
  17.             if (j - c[i] >= 0)  dp[i][j] = max(dp[i][j], dp[i - 1][j - c[i]] + a[i]);
  18.             dp[i][j] = max(dp[i][j], dp[i - 1][j]);
  19.             if (dp[i][j] >= m) ans = min(ans, j);
  20.         }
  21.     }
  22.     cout << ans;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement