Advertisement
sherry_ahmos

Untitled

Oct 18th, 2022
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <vector>
  4. #include <string>
  5. #include <queue>
  6. #include <map>
  7. #include <set>
  8. #include <string>
  9. #include <algorithm>
  10. #include <cmath>
  11. #include <unordered_map>
  12. #include <unordered_set>
  13. using namespace std;
  14.  
  15. #define ll long long
  16. #define nl endl
  17. #define cy cout << "YES\n"
  18. #define cn cout << "NO\n"
  19. #define sz(s) s.size()
  20. #define allv v.begin(), v.end()
  21. #define cin(vec) for (int i = 0; i < n && cin >> vec[i]; i++)
  22.  
  23. void sherry()
  24. {
  25.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  26. #ifndef ONLINE_JUDGE
  27.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  28. #endif
  29. }
  30. int n;
  31. ll x;
  32. vector<ll> v;
  33. bool rec(int i, ll sum)
  34. {
  35.     if (i > n)
  36.         return 0;
  37.     if (i == n)
  38.     {
  39.         return sum == x;
  40.     }
  41.     return rec(i + 1, sum + v[i]) || rec(i + 1, sum - v[i]);
  42. }
  43. void solve()
  44. {
  45.     cin >> n >> x;
  46.     v = vector<ll>(n);
  47.     cin(v);
  48.     rec(0, 0) ? cy : cn;
  49. }
  50.  
  51. int main()
  52. {
  53.     sherry();
  54.     ll t = 1;
  55.     // cin >> t;
  56.     while (t--)
  57.     {
  58.         solve();
  59.     }
  60.     return 0;
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement