Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- void chmin(int &a, int b) {
- if (a > b) a = b;
- }
- int main() {
- cin.tie(0)->sync_with_stdio(0);
- int n, l;
- cin >> n >> l;
- vector<int> a(n + 1);
- for (int i = 1; i <= n; i++) {
- cin >> a[i];
- }
- vector<vector<int>> dp(n + 1, vector<int>(1001, 1e7));
- dp[0][l] = 0;
- for (int i = 1; i <= n; i++) {
- for (int j = 0; j <= l; j++) {
- if (j >= a[i]) {
- chmin(dp[i][j - a[i]], dp[i - 1][j]);
- }
- chmin(dp[i][l - a[i]], max(dp[i - 1][j], j));
- }
- }
- int ans = 1e7;
- for (int i = 0; i <= l; i++) {
- chmin(ans, dp[n][i]);
- }
- cout << ans << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement