Skip to content
Programmingoneonone
Programmingoneonone
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

HackerEarth Alice and Bob buy crackers problem solution

YASH PAL, 31 July 2024
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.

#include<bits/stdc++.h>

#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'

/*constants*/
#define MAXN 100005
#define PI 3.14159265358979323846

/*debug*/
#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...);}
#else
#define trace(...)
#endif

using namespace std;


int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);

ll i,j,n,m,k,cnt=0,t=1;
cin>>n;
int c[n];
for(int i=0;i<n;i++){
cin>>c[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);
}
cout<<ans.size();

return 0;
}
coding problems solutions

Post navigation

Previous post
Next post

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes