Advertisement
Saleh127

CSES 1634

Apr 22nd, 2021
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. ll dp[1000005];
  6. int main()
  7. {
  8. ios_base::sync_with_stdio(0);
  9. cin.tie(0);cout.tie(0);
  10.  
  11.  
  12. ll n,m,i,j,k,l=1e9+7;
  13.  
  14. cin>>n>>m;
  15.  
  16. ll a[n+5];
  17.  
  18. for(i=0;i<n;i++)
  19. {
  20. cin>>a[i];
  21. }
  22.  
  23. for(i=1;i<=m;i++)
  24. {
  25. dp[i]=INT_MAX;
  26.  
  27. for(j=0;j<n;j++)
  28. {
  29. if(i>=a[j])
  30. {
  31. dp[i]=min(dp[i],dp[i-a[j]]+1ll);
  32. }
  33. }
  34.  
  35. }
  36.  
  37. if(dp[m]<INT_MAX) cout<<dp[m]<<endl;
  38. else cout<<-1<<endl;
  39.  
  40. return 0;
  41. }
  42.  
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement