Saturday, March 19, 2022

Buy 2 Get 1 Free

 There is a sale going on in Chefland. For every 

items Chef pays for, he gets the third item for free (see sample explanations for more clarity).

It is given that the cost of

item is rupees. Find the minimum money required by Chef to buy at least

items.

Input Format

  • First line will contain
  • , number of test cases. Then the test cases follow.
  • Each test case contains of a single line of input, two integers
  • and
    • .

    Output Format

    For each test case, output the minimum money required by Chef to buy at least

    items.

    Constraints

    Subtasks

    • Subtask 1 (100 points): Original constraints.

    Sample Input 1

    4
    3 4
    4 2
    5 3
    6 1
    

    Sample Output 1

    8
    6
    12
    4
    

    Explanation

    Test Case

    : Chef wants items where the cost of each item is rupees. To minimise the expenditure, Chef can pay for items and get the third item for free. This way, the total money required is

    rupees.

    Test Case

    : To minimise the expenditure, Chef can do the following:

    • Purchase
    items for rupees and get the third one free. Thus, the total number of items is
  • .
  • Purchase
  • item for rupees. Now Chef has total
    • items.

    Thus, the minimum money required to buy

    items is

    rupees.

    Test Case

    : To minimise the expenditure, Chef can do the following:

    • Purchase
    items for rupees and get the third one free. Thus, the total number of items is
  • .
  • Purchase
  • items for rupees. Chef gets a third item for free. Now Chef has total items which is greater than his requirement of
    • items.

    Chef wanted to buy at least

    items. The minimum money required for that is

    rupees.

    Test Case

    : To minimise the expenditure, Chef can do the following:

    • Purchase
    items for rupees and get the third one free. Thus, the total number of items is
  • .
  • Purchase
  • items for rupees and get the third one free.. Now Chef has total
    • items.

    Thus, the minimum money required to buy

    items is rupees.

    No comments:

    Post a Comment

    मुझे दिल में बसाना आसान नहीं....

    पता है Recently i realised की मुझे दिल में बसाना आसान नहीं है बात-बात पे चिढ़ जाती हूं मैं दिल लगा लूं एक बार तो फिर ज़िद पे अड़...