fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int W = 2e5 + 1;
  5. int cnt[W];
  6. int n, w;
  7.  
  8. int main()
  9. {
  10. ios_base::sync_with_stdio(false);
  11. cin.tie(0);
  12. cin >> n >> w;
  13. for (int i = 0; i < n; ++i) {
  14. int x;
  15. cin >> x;
  16. ++cnt[x];
  17. }
  18. for (int i = 1; i <= w; ++i) {
  19. auto carry = (cnt[i] - 1) / 2;
  20. if (carry) {
  21. cnt[2 * i] += carry;
  22. cnt[i] -= 2 * carry;
  23. }
  24. }
  25. bitset<W> knapsack = 1;
  26. for (int i = 1; i <= w; ++i)
  27. for (int j = 0; j < cnt[i]; ++j)
  28. knapsack |= knapsack << i;
  29. cout << (knapsack.test(w) ? "YES" : "NO");
  30. }
Success #stdin #stdout 0.01s 5424KB
stdin
Standard input is empty
stdout
YES