Header Ad

HackerEarth Alice and Bob buy crackers problem solution

In this HackerEarth, Alice and Bob buy crackers problem solution Alice and Bob want to buy firecrackers. There are N types of firecrackers available in the market with an ID I ranging from 1 to N. The cost of each firecracker is Ci. Each firecracker can be bought at most once. Bob's father allows him to spend all the money in any way but his only condition is that Alice and Bob receive equal amounts of money.

Your task is to determine the number of different amounts of money both can receive from Bob's father. You are given the cost of all crackers and the money according to the condition provided. 

In other words, let S be a set. For each subset of firecrackers, if the sum of the costs of these firecrackers is even, then add their sum to S and print the size of S. Note that the set does not contain equal elements.

HackerEarth Alice and Bob buy crackers problem solution

HackerEarth Alice and Bob buy crackers problem solution.


#define hell 1000000007
#define lcm(a,b) ((a*b)/__gcd(a,b))
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll vector< pair<ll,ll> >
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define F first
#define S second
#define rep(i,a,b) for(i=a;i<b;i++)
#define parr(a,n) for(ll it=0;it<n;it++) cout<<a[it]<<" ";cout<<endl;
#define pcont(a) for(auto it:a) cout<<it<<" ";cout<<endl;
#define ret(x) return cout<<x,0;
#define endl '\n'

#define MAXN 100005
#define PI 3.14159265358979323846

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>void __f(const char* name, Arg1&& arg1){ std::cout << name << " : " << arg1 << '\n';}
template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ','); std::cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#define trace(...)

using namespace std;

int main()

ll i,j,n,m,k,cnt=0,t=1;
int c[n];
for(int i=0;i<n;i++){
set<int> ans;
for(int i=1;i<(1<<n);i++){
int val=0;
for(int j=0;j<n;j++){
if(i&(1<<j)) val+=c[j];
if(val%2==0) ans.insert(val);

return 0;

Post a Comment