fork download
  1. // Problem :
  2.  
  3. #pragma GCC optimize("Ofast,unroll-loops,inline,fast-math")
  4. #pragma GCC target("avx2,sse4.2,bmi,bmi2,lzcnt,popcnt,fma")
  5.  
  6. #include <bits/stdc++.h>
  7.  
  8. #if LOCAL
  9. #include "algo/debug.h"
  10. #endif
  11.  
  12. #define task "sol"
  13.  
  14. using namespace std;
  15. using ll = long long;
  16.  
  17. constexpr int MOD = 1e9 + 7;
  18. constexpr int LIMIT = 1e6 + 7;
  19. constexpr ll INF = LLONG_MAX;
  20.  
  21. signed main() {
  22. ios_base::sync_with_stdio(false);
  23. cin.tie(nullptr); cout.tie(nullptr);
  24.  
  25. if (fopen(task".inp", "r")) {
  26. freopen(task".inp", "r", stdin), freopen(task".out", "w", stdout);
  27. }
  28.  
  29. int n, s;
  30. cin >> n >> s;
  31.  
  32. vector<int> arr(n);
  33.  
  34. for (int &val : arr) cin >> val;
  35.  
  36. vector<int> dp(s + 1, 0);
  37. dp[0] = 1;
  38.  
  39. for (const int &val : arr) {
  40. for (int w = val; w <= s; ++w) {
  41. (dp[w] += dp[w - val]) %= MOD;
  42. }
  43. }
  44.  
  45. cout << dp.back();
  46.  
  47. return 0;
  48. }
  49.  
Success #stdin #stdout 0.37s 5324KB
stdin
Standard input is empty
stdout
Standard output is empty