Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <cmath>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- vector <int> a,b(2001);
- int n, k,q(-1),min(1e9);
- cin >> n;
- a.resize(n);
- for (int i(0); i < n; i++)
- {
- cin >> a[i];
- b[a[i]] = 1;
- }
- cin >> k;
- b.resize(k+1);
- sort(a.begin(), a.end());
- for (int i(1); i <= k; i++)
- {
- if (b[i] != 1){
- for (int j(0); j < n; j++)
- if (a[j] < i)
- q = j;
- for (int j(0); j <= q; j++)
- if (b[i - a[j]] < min)
- min = b[i - a[j]];
- b[i] = min + 1;
- min = 1e9;
- }
- }
- if (b[k] == 1e9+1)
- cout << -1;
- else
- cout << b[k];
- return 0;
- }
- /*
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement