Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 1e6 + 3;
- int n, x;
- int dp[N], a[N];
- int main(){
- cin >> n >> x;
- for (int i = 1; i <= n; i++) {
- cin >> a[i];
- }
- for (int i = 1; i <= x; i++) {
- dp[i] = 1e7;
- }
- for (int i = 1; i <= n; i++) {
- for (int j = a[i]; j <= x; j++) {
- dp[j] = min(dp[j], dp[j - a[i]] + 1);
- }
- }
- if (dp[x] == 1e7) dp[x] = -1;
- cout << dp[x] << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment