Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define N 101
  3.  
  4. using namespace std;
  5.  
  6. int n, m;
  7. int a[N], d[INF];
  8. const int INF = 10005;
  9.  
  10. int main() {
  11. cin >> n >> m;
  12. for (int i = 1; i <= n; i++)
  13. cin >> a[i];
  14. for (int i = 1; i <= m; i++)
  15. d[i] = INF;
  16. sort(a + 1, a + n + 1);
  17. for (int i = 1; i <= n; i++) {
  18. for (int j = 0; j <= m; j++) {
  19. if(j - a[i] >= 0)
  20. d[j] = min(d[j], d[j - a[i]] + 1);
  21. }
  22. }
  23. if (d[m] != INF) cout << d[m];
  24. else cout << 0;
  25. }
  26. /**6 10
  27. 1 1 1 5 5 7*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement