HackerRank ‘Taum and B’day’ Solution

Short Problem Definition:

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 number of black gifts and W number of white gifts.


Taum and B’day


time complexity is O(1)

space complexity is O(1)


The cost for each present is either the cost of its category, or the cost of the other category + the conversion cost. Just select the minimum.

if __name__ == '__main__':
    t = input()
    for _ in xrange(t):
        b, w = map(int, raw_input().split())
        x, y, z = map(int, raw_input().split())
        print min(b*x, b*(y+z)) + min(w*(x+z), w*y)

If you enjoyed this post, then make sure you subscribe to my Newsletter and/or Feed.