Advertisement
tuki2501

PTRANG_O(NL)

Sep 19th, 2022
808
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5.  
  6. void chmin(int &a, int b) {
  7.     if (a > b) a = b;
  8. }
  9.  
  10. int main() {
  11.     cin.tie(0)->sync_with_stdio(0);
  12.     int n, l;
  13.     cin >> n >> l;
  14.     vector<int> a(n + 1);
  15.     for (int i = 1; i <= n; i++) {
  16.         cin >> a[i];
  17.     }
  18.     vector<vector<int>> dp(n + 1, vector<int>(1001, 1e7));
  19.     dp[0][l] = 0;
  20.     for (int i = 1; i <= n; i++) {
  21.         for (int j = 0; j <= l; j++) {
  22.             if (j >= a[i]) {
  23.                 chmin(dp[i][j - a[i]], dp[i - 1][j]);
  24.             }
  25.             chmin(dp[i][l - a[i]], max(dp[i - 1][j], j));
  26.         }
  27.     }
  28.     int ans = 1e7;
  29.     for (int i = 0; i <= l; i++) {
  30.         chmin(ans, dp[n][i]);
  31.     }
  32.     cout << ans << '\n';
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement