In this post, we will solve **Taum and B’day HackerRank Solution**. This problem **(Taum and B’day)** is a part of **HackerRank Algorithms** series.

**Task**

Taum is planning to celebrate the birthday of his friend, Diksha. There are two types of gifts that Diksha wants from Taum: one is black and the other is white. To make her happy, Taum has to buyÂ * b*Â black gifts andÂ

*Â white gifts.*

**w**- The cost of each black gift isÂ
Â units.**bc** - The cost of every white gift isÂ
Â units.**wc** - The cost to convert a black gift into white gift or vice versa isÂ
Â units.**z**

Determine the minimum cost of Diksha’s gifts.

**Example***b* = 3*w* = 5*bc* = 3*wc* = 4*z* = 1

He can buy a black gift forÂ **3**Â and convert it to a white gift forÂ **1**, making the total cost of each white giftÂ **4**. That matches the cost of a white gift, so he can do that or just buy black gifts and white gifts. Either way, the overall cost isÂ **3 * 3 + 5 * 4 = 29**.

**Function Description**

Complete the function *taumBday* in the editor below. It should return the minimal cost of obtaining the desired gifts.

taumBday has the following parameter(s):

*int b*: the number of black gifts*int w*: the number of white gifts*int bc*: the cost of a black gift*int wc*: the cost of a white gift*int z*: the cost to convert one color gift to the other color

**Returns**

*int:*Â the minimum cost to purchase the gifts

**Input Format**

The first line will contain an integerÂ * t*, the number of test cases.

The nextÂ * t*Â pairs of lines are as follows:

– The first line contains the values of integersÂ

*Â andÂ*

**b***.*

**w**– The next line contains the values of integersÂ

*,Â*

**bc***, andÂ*

**wc***.*

**z****Constraints**

**1 <=***t*<= 10**0 <=***b*,*w*,*bc*,*wc*,*z*<= 10^{9}

**Output Format**

Â * t* lines, each containing an integer: the minimum amount of units Taum needs to spend on gifts.

**Sample Input**

```
STDIN Function
----- --------
5 t = 5
10 10 b = 10, w = 10
1 1 1 bc = 1, wc = 1, z = 1
5 9 b = 5, w = 5
2 3 4 bc = 2, wc = 3, z = 4
3 6 b = 3, w = 6
9 1 1 bc = 9, wc = 1, z = 1
7 7 b = 7, w = 7
4 2 1 bc = 4, wc = 2, z = 1
3 3 b = 3, w = 3
1 9 2 bc = 1, wc = 9, z = 2
```

**Sample Output**

```
20
37
12
35
12
```

**Explanation**

*Test Case #01:*

Since black gifts cost the same as white, there is no benefit to converting the gifts. Taum will have to buy each gift forÂ*1*Â unit. The cost of buying all gifts will be:Â.*b***bc*+*w***wc*= 10 * 1 + 10 * 1 = 20*Test Case #02:*

Again, he cannot decrease the cost of black or white gifts by converting colors.Â Â is too high. He will buy gifts at their original prices, so the cost of buying all gifts will be:Â.*b***bc*+*w***wc*= 5 * 2 + 9 * 3 = 10 + 27 = 37*Test Case #03:*

SinceÂ, he will buyÂ*bc*>*wc*+ zÂ white gifts at their original price ofÂ*b*+*w*= 3 + 6 = 9**1**.ÂÂ of the gifts must be black, and the cost per conversion,Â*b*= 3. Total cost isÂ*z*= 1**9 * 1 + 3 * 1 = 12**.*Test Case #04:*

Similarly, he will buyÂÂ white gifts at their original price,Â*w*= 7. For black gifts, he will first buy white ones and color them to black, so that their cost will be reduced toÂ*wc*= 2. So cost of buying all gifts will be:Â*wc*+*z*= 2 + 1 = 3**7 * 3 + 7 * 2 = 35**.*Test Case #05:*Â He will buy black gifts at their original price,Â. For white gifts, he will first black gifts worthÂ*bc*= 1Â unit and color them to white forÂ*bc*= 1Â units. The cost for white gifts is reduced toÂ*z*= 2Â units. The cost of buying all gifts will be:Â*wc*=*bc*+*z*= 2 + 1 = 3**3 * 1 + 3 * 3 = 3 + 9 = 12**.

**Solution – Taum and B’day – HackerRank Solution**

**C++**

#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; int main() { int cases; scanf("%d", &cases); while (cases--) { int B, W, X, Y, Z; scanf("%d %d %d %d %d", &B, &W, &X, &Y, &Z); long long res = (long long)B * X + (long long)W * Y; res = min(res, (long long)B * X + (long long)W * (X + Z)); res = min(res, (long long)B * (Y + Z) + (long long)W * Y); printf("%lld\n", res); } return 0; }

**Python**

#!/bin/python3 import os import sys # # Complete the taumBday function below. # def taumBday(b, w, bc, wc, z): res = 0 if bc <= wc: res += bc*b if bc + z <= wc: res += (bc + z)*w else: res += wc*w else: res += wc*w if wc + z <= bc: res += (wc + z)*b else: res += bc*b return res if __name__ == '__main__': fptr = open(os.environ['OUTPUT_PATH'], 'w') t = int(input()) for t_itr in range(t): bw = input().split() b = int(bw[0]) w = int(bw[1]) bcWcz = input().split() bc = int(bcWcz[0]) wc = int(bcWcz[1]) z = int(bcWcz[2]) result = taumBday(b, w, bc, wc, z) fptr.write(str(result) + '\n') fptr.close()

**Java**

import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { int m; long b,w,x,y,z; long v1,v2,v3,v4,s; Scanner in = new Scanner(System.in); m = in.nextInt(); while(m!=0) { b = in.nextLong(); w = in.nextLong(); x = in.nextLong(); y = in.nextLong(); z = in.nextLong(); v1=0L;v2=0L;v3=0L;v4=0L;s=0L; v1 = (b*x)+(w*y); v2 = (b*z)+(b*y) + (w*z)+(w*x); if(v1<=v2) s=v1; else s=v2; v3 = (b*x) + (w*z)+(w*x); if(v3<=s) s=v3; v4 = (b*z)+(b*y) + (w*y);; if(v4<=s) s=v4; System.out.println(s); m--; } } }

**Note:** This problem **(Taum and B’day)** is generated by **HackerRank** but the solution is provided by **CodingBroz**. This tutorial is only for **Educational** and **Learning** purpose.