Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 1e6 + 5;
- int dp[N], n, x, ar[105], ans = 2e9;
- main()
- {
- cin >> n >> x;
- for (int i = 1; i <= n; i++)
- scanf("%d", &ar[i]);
- memset(dp, 0x3f3f3f3f, sizeof(dp));
- dp[0] = 0;
- for (int i = 1; i <= x; i++)
- {
- int sum = 0;
- for (int j = 1; j <= n; j++)
- {
- sum += ar[j];
- if (i >= sum)
- {
- dp[i] = min( dp[i], dp[i - sum] + j + 1 );
- if ( j == n && (x - i) % ar[n] == 0 )
- ans = min(ans, dp[i - sum] + j + 1 + (x - i) / ar[n]);
- }
- }
- }
- ans = min(ans, dp[x]);
- if (ans > 1e9)
- ans = 0;
- cout << ans - 1 << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement