# Daily HackerRank Challenge - Day 19

Daily HackerRank Challenge (30 Part Series)

This is a series of Daily HackerRank Challenge. Each day I show the some solutions written in C++.

# Taum and B'day

Sample Input

5
10 10
1 1 1
5 9
2 3 4
3 6
9 1 1
7 7
4 2 1
3 3
1 9 2


Sample Output

20
37
12
35
12


We need to find out that if it is worth to convert one color gift to the other color based on the cost z. Basically we only do that when wc+z is less than bc for black gifts

b*min(bc,wc+z)


or when bc+z is less than wc for white gifts.

w*min(wc,bc+z))


so the answer is their sum.

b*min(bc,wc+z) + w*min(wc,bc+z)


Final Solution

int t;
long b,w,bc,wc,z;

int main()
{
FAST_INP;
cin>>t;
TC(t){
cin>>b>>w>>bc>>wc>>z;
cout << (b*min(bc,wc+z) + w*min(wc,bc+z)) << "\n";
}

return 0;
}


# Complete Code

Check out the complete code via below links

Daily HackerRank Challenge (30 Part Series)

Posted on by:

### Wing-Kam

Consultant by day. Developer by night. AWS certified. Exploring #CloudNative currently.