371C Hamburgers

Problem Link

In this problem, it’s very simple problem real life problem

Here,you need to make max number of hamburgers

How to do it :

  Here , first you need to count how many bread ,sausage and cheese will be used to make One Hamburgers and question is how many?

               There is an efficient approach , use binary search to find the amounts 😛

and the cost will be in your budget ,it is a greedy problem 😉


View Code

using namespace std;
int co=0;


int main()
long long nc,nb,ns,ps,pb,pc,p;

string s;long long mn=0;
for(int i=0;i<s.size();i++) ++mp[s[i]]; cin>>nb>>ns>>nc;
long long mx=1e15;
long long cost;
while(mn+1<mx) { long long md=(mx+mn)>>1;
long long cb=pb*((mp[‘B’]*md>nb)?mp[‘B’]*md-nb:0);

long long cs=ps*((mp[‘S’]*md>ns)?mp[‘S’]*md-ns:0);
long long cc=pc*((mp[‘C’]*md>nc)?mp[‘C’]*md-nc:0);

if(cost<=p) mn=md;
else mx=md;





Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s