Buy Lamps Codechef Problem Solution

An electronics shop sells red and blue lamps. A red lamp costs rupees and a blue lamp costs rupees.

Chef is going to buy exactly lamps from this shop. Find the minimum amount of money Chef needs to pay such that at least of the lamps bought are red.

Input Format

• The first line of input will contain a single integer , denoting the number of test cases.
• Each test case consists of a single line containing four space-separated integers

Output Format

For each test case, output on a new line the minimum amount of money Chef needs to pay in order to buy lamps such that at least of the lamps bought are red.

Sample Input 1

4
2 2 5 1
4 1 3 1
3 0 4 7
5 2 3 4


Sample Output 1

10
6
12
15


Explanation

Test case : Chef buys red lamps with rupees.

Test case : Chef buys red lamp and blue lamps with rupees.

Test case : Chef buys red lamps with rupees.

				
/* package codechef; // don't place package name! */

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 sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int k=sc.nextInt();
int x=sc.nextInt();
int y=sc.nextInt();

int r=n-k;
int ans = k*x;

int a=x<y?x:y;
ans+=r*a;

System.out.println(ans);
}

}