Problem
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 - the number of test cases. Then the test cases follow.
- The first line of each test case contains three space-separated integers , , and - 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
Sample 1:
4 0 0 100 10 1 0 1000 10 1000 10 7 1
0 0 10000 3
Explanation:
- Test case : Chef has no pairs to sell, so the amount obtained is .
- Test case : The amount earned by selling a pair is , so the total amount obtained is .
- Test case : Chef can sell pairs of slippers, each giving rupees, so the total amount earned is .
- Test case : Chef has slippers of which are left and are right. Therefore Chef can sell a maximum of pairs and in total can get at most .
Program :
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner in = new Scanner(System.in);
int t= in.nextInt();
while(t -- > 0)
{
int n = in.nextInt();
int l = in.nextInt();
int x = in.nextInt();
System.out.println(Math.min(l,Math.abs(n-l)) * x);
}
}
}
0 Comments