Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <cstdlib>
- #include <algorithm>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- #define ll long long
- void sherry()
- {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- int a;
- ll b;
- int arr[20];
- int ind = 0;
- ll sum = 0;
- bool recursion(ll sum, int ind)
- {
- if (ind == a)
- {
- return sum == b;
- }
- return recursion(sum + arr[ind], ind + 1) || recursion(sum - arr[ind], ind + 1);
- }
- int main()
- {
- sherry();
- cin >> a >> b;
- for (int i = 0; i < a; i++)
- cin >> arr[i];
- recursion(0, 0) ? cout << "YES" : cout << "NO";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement