Advertisement
esraa_syam

Untitled

Oct 15th, 2022
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define nl "\n"
  3. #define fi first
  4. #define se second
  5. #define pi 3.14159
  6. #define ll long long
  7. #define odd(a) (a&1)
  8. #define even(a) !(a&1)
  9. #define Mod 1'000'000'007
  10. #define INF 2'000'000'000
  11. #define sz(x) int(x.size())
  12. #define charToInt(s) (s - '0')
  13. #define ull unsigned long long
  14. #define all(s) s.begin(), s.end()
  15. #define rall(v) v.rbegin() , v.rend()
  16. #define fixed(n) fixed << setprecision(n)
  17. #define Num_of_Digits(n) ((int)log10(n) + 1)
  18. #define to_decimal(bin) stoll(bin, nullptr, 2)
  19. #define Ceil(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  20. #define Floor(n, m) (((n) / (m)) - ((n) % (m) ? 0 : 1))
  21. #define Upper(s) transform(all(s), s.begin(), ::toupper);
  22. #define Lower(s) transform(all(s), s.begin(), ::tolower);
  23. #define cout_map(mp) for(auto& [f, s] : mp) cout << f << " " << s << "\n";
  24. // ----- bits-------
  25. #define pcnt(n) __builtin_popcount(n)
  26. #define pcntll(n) __builtin_popcountll(n)
  27. #define clz(n) __builtin_clz(n) // <---100
  28. #define clzll(n) __builtin_clzll(n)
  29. #define ctz(n) __builtin_ctz(n) // 0001---->
  30. #define ctzll(n) __builtin_ctzll(n)
  31.  
  32. using namespace std;
  33.  
  34. template < typename T = int > istream& operator >> (istream &in, vector < T > & v){
  35. for(auto & x : v) in >> x;
  36. return in;
  37. }
  38.  
  39. template < typename T = int > ostream& operator << (ostream &out, const vector < T > & v){
  40. for(const T & x : v) out << x << " ";
  41. return out;
  42. }
  43. #include <bits/stdc++.h>
  44. #include <ext/pb_ds/assoc_container.hpp>
  45. #include <ext/pb_ds/tree_policy.hpp>
  46.  
  47. using namespace std;
  48. using namespace __gnu_pbds;
  49.  
  50. template <typename K, typename V, typename Comp = std::less<K>>
  51. using ordered_map = tree<K, V, Comp, rb_tree_tag, tree_order_statistics_node_update>;
  52. template <typename K, typename Comp = std::less<K>>
  53. using ordered_set = ordered_map<K, null_type, Comp>;
  54.  
  55. template <typename K, typename V, typename Comp = std::less_equal<K>>
  56. using ordered_multimap = tree<K, V, Comp, rb_tree_tag, tree_order_statistics_node_update>;
  57. template <typename K, typename Comp = std::less_equal<K>>
  58. using ordered_multiset = ordered_multimap<K, null_type, Comp>;
  59.  
  60. void esraa()
  61. {
  62. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  63. #ifndef ONLINE_JUDGE
  64. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  65. #endif
  66. }
  67. ll n;
  68. vector < ll > v;
  69. bool rec(ll i , ll target , ll sum){
  70. // base case
  71. if(i == n){
  72. if(sum == target) return true;
  73. return false;
  74. }
  75. // recursive case
  76. return rec(i + 1 , target , sum + v[i]) || rec(i + 1 , target , sum - v[i]) ;
  77.  
  78. }
  79. void solve(){
  80. ll target;
  81. cin >> n >> target;
  82. v.resize(n);
  83. cin >> v;
  84. cout << (rec(0 , target , 0) ? "YES" : "NO") << nl;
  85. }
  86. int main()
  87. {
  88. esraa();
  89. int t = 1;
  90. //cin >> t;
  91. while(t--)
  92. solve();
  93. return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement