Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <map>
- //#include <bits/stdc++.h>
- #include <algorithm>
- #include <cmath>
- using namespace std;
- #define ll long long
- #define cy cout << "YES"
- #define cn cout << "NO"
- #define nl "\n"
- #define fi first
- #define se second
- #define all(v) v.begin(), v.end()
- #define sz(s) s.size()
- template <typename T = int>
- istream &operator>>(istream &in, vector<T> &v)
- {
- for (auto &x : v)
- in >> x;
- return in;
- }
- template <typename T = int>
- ostream &operator<<(ostream &out, const vector<T> &v)
- {
- for (const T &x : v)
- out << x << " ";
- return out;
- }
- void sherry()
- {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- ll n, x;
- vector<ll> v, dp;
- ll coins(ll curr)
- {
- if (curr == 0)
- return 0;
- ll &ret = dp[curr];
- if (~ret)
- return ret;
- ret = 1e9;
- for (ll i = 0; i < n; i++)
- {
- if (curr - v[i] >= 0)
- {
- ret = min(ret, 1 + coins(curr - v[i]));
- }
- }
- return ret;
- }
- void solve()
- {
- cin >> n >> x;
- v.resize(n);
- cin >> v;
- dp.assign(1e6, -1);
- int ans = coins(x);
- if (ans == 1e9)
- cout << "-1";
- else
- cout << ans;
- }
- int main()
- {
- sherry();
- int t = 1;
- // cin >> t;
- while (t--)
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement