fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N=105, MAXS=1e5+5;
  5. int n, v[N], S, dp[MAXS];
  6.  
  7. int main()
  8. {
  9. ios::sync_with_stdio(0);
  10. cin.tie(0); cout.tie(0);
  11.  
  12. cin >> n >> S;
  13. for(int i=1;i<=n;++i)
  14. cin >> v[i];
  15. for(int j=0;j<=S;++j) dp[j]=1e9;
  16. dp[0]=0;
  17. for(int i=1;i<=n;++i){
  18. for(int j=v[i];j<=S;++j){
  19. dp[j]=min(dp[j], dp[j-v[i]]+1);
  20. }
  21. }
  22. cout << dp[S];
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty