Taum and B'day

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 w white gifts.

1.The cost of each black gift is bc units.

2.The cost of every white gift is wc units.

3.The cost to convert a black gift into a white gift or vice versa is z units.

Determine the minimum cost of Diksha's gifts.

Example:

Input:  b=3,w=6,bc=9,wc=1,z=1
Output: 12

Approach

C++

#include <bits/stdc++.h>
using namespace std;

long taumBday(long blong wlong bclong wclong z)
{
    if (bc < wc && (wc - bc) > z)
    {
        return b * bc + w * bc + z * w;
    }
    else if (wc < bc && (bc - wc) > z)
    {
        return b * wc + wc * w + z * b;
    }
    return b * bc + w * wc;
}

int main()
{
    int b = 3, w = 6;
    int bc = 9, wc = 1, z = 1;
    cout << taumBday(b, w, bc, wc, z);
    return 0;
}


No comments:

Post a Comment