Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ___T_
- | - + |
- |__v__|
- .=[::+]=.
- ]=' [___] '=[ => HI :-)
- / |
- _\ |_
- */
- #include<bits/stdc++.h>
- using namespace std;
- using lli = int64_t;
- const int maxN = 1000;//sum of elements
- int main(){
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- //check if subset sum exist or not using bitset
- int n,sum;
- bitset<maxN> bit;
- bit[0] = 1; //we can make sum = 0 without any eleemnts;
- cin >> n >> sum;
- for(int i = 0;i < n; i++){
- int in;
- cin >> in;
- bit |= (bit << in);
- }
- if(bit[sum]){
- cout << "YES";
- }else{
- cout << "NO";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement