Taum & B'day
Code
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t,i;
cin>>t; // input no of test cases
for(i=0;i<t;i++)
{
long int b,w,bc,wc,z,total;
cin>>b>>w>>bc>>wc>>z; // taking input requirements
if((bc+z)<wc) // if cost of purchasing a black gift and converting it into white is less than the actual cost then he will do the same hence the cost is reset to which he buys the gift
{
wc=bc+z;
}
else if((wc+z)<bc) // if cost of purchasing a white gift and converting it into black is less than the actual cost then he will do the same hence the cost is reset to which he buys the gift
{
bc=wc+z;
}
total=b*bc+w*wc; // finally calculate the total cost by using the cost which he buys every thing
cout<<total<<endl;
}
return 0;
}
Taum & B'day Hackerrank Solution in C++
You can post your own solutions in any language in comments section we will review and post with your credits.
0 Comments