Coding Question 1



Chef and Pairing Slippers (CODECHEF OCTOBER COOK-OFF CHALLENGE 2021)


Chef has slippers,  of which are left slippers and the rest are right slippers. Slippers must always be sold in pairs, where each pair contains one left and one right slipper. If each pair of slippers cost rupees, what is the maximum amount of rupees that Chef can get for these slippers?

Input Format

  • The first line contains T - the number of test cases. Then the test cases follow.
  • The first line of each test case contains three space-separated integers NL, and X - the total number of slippers, the number of left slippers, and the price of a pair of slippers in rupees.

Output Format

For each test case, output on one line the maximum amount of rupees that Chef can get by selling the slippers that are available.

Constraints

  • 1T103
  • 0LN103

Sample Input 1 

4
0 0 100
10 1 0
1000 10 1000
10 7 1

Sample Output 1 

0
0
10000
3

Explanation

  • Test case : Chef has no pairs to sell, so the amount obtained is 0.
  • Test case : The amount earned by selling a pair is 0, so the total amount obtained is 0.
  • Test case : Chef can sell 10 pairs of slippers, each giving 1000 rupees, so the total amount earned is 100010=10000.
  • Test case : Chef has 10 slippers of which 7 are left and 3 are right. Therefore Chef can sell a maximum of 3 pairs and in total can get at most 31=3

Code:

    for i in range(int(input())):
        N,L,X=map(int,input().split())
        if((N-L)<=L):
            print((N-L)*X)
        elif((N-L)>=L):
            print(L*X)
        else:
            print(0)

LINK: https://www.codechef.com/COOK134C/problems/CHEFSLP

Please follow the page for more updates....!

Comments

Popular posts from this blog