Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define endl "\n"
- using namespace std;
- using ll = long long;
- using ld = long double;
- using pii = pair<int, int>;
- constexpr int N = 1e4+5;
- int n, m, weight[N];
- int dp[N];
- void Solve()
- {
- cin >> n >> m;
- fill(dp, dp+N, INT32_MAX);
- for (int i = 1; i <= n; i++)
- cin >> weight[i];
- dp[0] = 0;
- for (int i = 1; i <= n; i++)
- for (int j = m; j >= weight[i]; j--)
- if (dp[j - weight[i]] != INT32_MAX)
- dp[j] = min(dp[j - weight[i]] + 1, dp[j]);
- cout << (dp[m] == INT32_MAX ? 0 : dp[m]);
- }
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- Solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement