Hello Programmers, In this post, you will learn how to solve** HackerRank Taum and Bday Solution**. This problem is a part of the ** HackerRank Algorithms** Series.

One more thing to add, don’t straight away look for the solutions, first try to solve the problems by yourself. If you find any difficulty after trying several times, then look for the solutions. We are going to solve the HackerRank Algorithms problems using C, CPP, JAVA, PYTHON, JavaScript & SCALA Programming Languages.

You can practice and submit all HackerRank problem solutions in one place. Find a solution for other domains and Sub-domain. I.e. Hacker Rank solution for HackerRank C Programming, HackerRank C++ Programming, HackerRank Java Programming, HackerRank Python Programming, HackerRank Linux Shell, HackerRank SQL Programming, and HackerRank 10 days of Javascript.

As you already know that this site does not contain only the Hacker Rank solutions here, you can also find the solution for other problems. I.e. Web Technology, Data Structures, RDBMS Programs, Java Programs Solutions, Fiverr Skills Test answers, Google Course Answers, Linkedin Assessment, and Coursera Quiz Answers.

## HackerRank Taum and Bday Pairs

### 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*+ zwhite 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 buywhite 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*= 1unit and color them to white for*bc*= 1units. The cost for white gifts is reduced to*z*= 2units. The cost of buying all gifts will be:*wc*=*bc*+*z*= 2 + 1 = 3**3 * 1 + 3 * 3 = 3 + 9 = 12**.

## HackerRank Taum and Bday Solution

### Taum and Bday Solution in C

#include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> long int min(long int a, long int b, long int c); int main() { int t; long int b,w,x,y,z; scanf("%d",&t); while(t--) { long int sum=0; long int sum1=0,sum2=0; scanf("%ld%ld",&b,&w); scanf("%ld%ld%ld",&x,&y,&z); sum=b*x+w*y; sum1=(b+w)*x+w*z; sum2=(b+w)*y+b*z; printf("%ld\n",min(sum,sum1,sum2)); } /* Enter your code here. Read input from STDIN. Print output to STDOUT */ return 0; } long int min(long int a,long int b, long int c) { if(a<=b&&a<=c) return a; if(b<=a&&b<=c) return b; return c; }

### Taum and Bday Solution in Cpp

#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; }

### Taum and Bday Solution in 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--; } } }

### Taum and Bday Solution in Python

def solve(b, w, x, y, z) : return b*min(x, y+z) + w*min(y, x+z) for _ in xrange(int(input())) : bw = map(int, raw_input().split()) b, w = bw[0], bw[1] xyz = map(int, raw_input().split()) x, y, z = xyz[0], xyz[1], xyz[2] print solve(b, w, x, y, z)

### Taum and Bday Solution using JavaScript

function getBigProduct(a, b) { var s = '', r = 0, da, p; if (a == 0 || b == 0) return '0'; while (a > 0) { da = a%10; a = Math.floor(a/10); p = da*b + r; if (p >= 10) { r = Math.floor(p/10); p = p%10; } else { r = 0; } s = p + s; } if (r > 0) s = r + s; return s; } function getBigSum(a, b) { var s = '', tmp, i, j, da, db, add, r = 0; if (a.length > b.length) { tmp = a; a = b; b = tmp; } i = a.length-1; j = b.length-1; for (i; i>=0; i--, j--) { da = parseInt(a[i]); db = parseInt(b[j]); add = da + db + r; if (add >= 10) { r = 1; add -= 10; } else { r = 0; } s = add + s; } for (j; j>=0; j--) { db = parseInt(b[j]); add = db + r; if (add > 10) { r = 1; add -= 10; } else { r = 0; } s = add + s; } if (r > 0) s = r + s; return s; } function getMinimumPrice(b, w, x, y, z) { if (x > y + z) x = y + z; else if (y > x + z) y = x + z; return getBigSum(getBigProduct(b,x), getBigProduct(w,y)); } function processData(input) { var t, b, w, x, y, z, i, l; input = input.split('\n'); t = parseInt(input[0]); for (i=0; i<t; i++) { l = input[i*2 + 1].split(' '); b = parseInt(l[0]); w = parseInt(l[1]); l = input[i*2 + 2].split(' '); x = parseInt(l[0]); y = parseInt(l[1]); z = parseInt(l[2]); console.log(getMinimumPrice(b, w, x, y, z)); } } process.stdin.resume(); process.stdin.setEncoding("ascii"); _input = ""; process.stdin.on("data", function (input) { _input += input; }); process.stdin.on("end", function () { processData(_input); });

### Taum and Bday Solution in Scala

import scala.io.StdIn._ import scala.math.min object Solution { def price(b: Int, w: Int, x: Int, y: Int): Long = b.toLong * x + w.toLong * y def solveTest(b: Int, w: Int, x: Int, y: Int, z: Int): Long = price(b, w, min(x, y + z), min(y, x + z)) def main(args: Array[String]) { val t = readInt() (0 to t - 1).map((t) => { val Array(b, w) = readLine().split("\\s+").map(_.toInt) val Array(x, y, z) = readLine().split("\\s+").map(_.toInt) solveTest(b, w, x, y, z) }).foreach(println) } }

### Taum and Bday Solution in Pascal

var t: Byte; b, w, x, y, z: Longint; begin ReadLn(t); while ( t > 0 ) do begin t := t - 1; ReadLn(b, w); ReadLn(x, y, z); if ( x > y + z ) then x := y + z else if ( y > x + z ) then y := x + z; WriteLn(b * x + w * y); end; end.

**Disclaimer:** This problem **(Taum and Bday)** is generated by **HackerRank** but the solution is provided by ** Chase2learn**. This tutorial is only for

**Educational**and

**Learning**purposes.

## FAQ:

**1. How do you solve the first question in HackerRank?**

If you want to solve the first question of Hackerrank then you have to decide which programing language you want to practice i.e C programming, Cpp Programing, or Java programming then you have to start with the first program HELLO WORLD.

**2. How do I find my HackerRank ID?**

You will receive an email from HackerRank to confirm your access to the ID. Once you have confirmed your email, the entry will show up as verified on the settings page. You will also have an option to “Make primary”. Click on that option. Read more

**3. Does HackerRank detect cheating?**

yes, HackerRank uses a powerful tool to detect plagiarism in the candidates’ submitted code. The Test report of a candidate highlights any plagiarized portions in the submitted code and helps evaluators to verify the integrity of answers provided in the Test.

**4. Does HackerRank use camera?**

No for coding practice Hackerrank does not use camera but for companies’ interviews code submission time Hackerrank uses the camera.

**5. Should I put HackerRank certificate on resume?**

These certificates are useless, and you should not put them on your resume. The experience you gained from getting them is not useless. Use it to build a portfolio, and link to it on your resume.

**6. Can I retake HackerRank test?**

The company which sent you the HackerRank Test invite owns your Test submissions and results. It’s their discretion to permit a reattempt for a particular Test. If you wish to retake the test, we recommend that you contact the concerned recruiter who invited you to the Test and request a re-invite.

**7. What is HackerRank?**

HackerRank is a tech company that focuses on competitive programming challenges for both consumers and businesses. Developers compete by writing programs according to provided specifications. Wikipedi

Finally, we are now, in the end, I just want to conclude some important message for you

**Note:-** I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Please share our posts on social media platforms and also suggest to your friends to Join Our Groups. Don’t forget to subscribe.