Lorem ipsum dolor sit amet, consectetur adipiscing elit. Test link

Correct Slippers : CORRSLP | CodeChef Solution

2 min read


Problem

Chef has NN slippers, LL 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 XX rupees, what is the maximum amount of rupees that Chef can get for these slippers?

Input Format

  • The first line contains TT - the number of test cases. Then the test cases follow.

  • The first line of each test case contains three space-separated integers NN, LL, and XX - 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

  • 0 \leq L \leq N \leq 10^3
  • 0 \leq X \leq 10^3
  • 1 \leq T \leq 100

Example / Sample:

Input:
4
0 0 100
10 1 0
1000 10 1000
10 7 1

Output:

0
0
10000
3

Explanation

  • Test case 1: Chef has no pairs to sell, so the amount obtained is 0.
  • Test case 2: The amount earned by selling a pair is 0, so the total amount obtained is 0.
  • Test case 3: Chef can sell 10 pairs of slippers, each giving 1000 rupees, so the total amount earned is 1000 \cdot 10 = 10000.
  • Test case 4: 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 3 \cdot 1 = 3.
  • Solution

    #include <iostream>
    using namespace std;

    // Solution from : Code Radius [ https://radiuscode.blogspot.com/ ]

    int main() {
    int t;
    cin>>t;
    while(t--) {
    int n,l,x;
    cin>>n>>l>>x;
    if(l>=n-l) {
    cout<<(n-l)*x<<endl;
    }
    else {
    cout<<l*x<<endl;
    }
    }
    return 0;
    }

    Please First Try to Solve Problem by Yourself.

    You may like these posts

    • ProblemChef is a big fan of Coldplay. Every Sunday, he will drive to a park taking MM minutes to reach there, and during the ride he will play a single song on a loop. Today, he ha…
    • ProblemWrite a program to obtain length (L)(L) and breadth (B)(B) of a rectangle and check whether its area is greater or perimeter is greater or both are equal.Input FormatFirst l…
    • ProblemGru has not been in the limelight for a long time and is, therefore, planning something particularly nefarious. Frustrated by his minions' incapability which has kept him aw…
    • ProblemAlice and Bob are meeting after a long time. As usual they love to play some math games. This times Alice takes the call and decides the game. The game is very simple, Alice…
    •  ProblemIn a coding contest, there are prizes for the top rankers. The prize scheme is as follows:Top 10 participants receive rupees X each.Participants with rank 11 to 100 (b…
    • ProblemYou and your friend are playing a game with hoops. There are NN hoops (where NN is odd) in a row. You jump into hoop 11, and your friend jumps into hoop NN. Then you jump in…

    Post a Comment