# [Solution] Buy Lamps solution codechef

Buy Lamps solution codechef – An electronics shop sells red and blue lamps. A red lamp costs XX rupees and a blue lamp costs YY rupees.

## [Solution] Buy Lamps solution codechef

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

### Input Format

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

### Output Format

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

## [Solution] Buy Lamps solution codechef

• 1T1031≤T≤103
• 1N1081≤N≤108
• 0KN0≤K≤N
• 1X,Y101≤X,Y≤10

### 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


## [Solution] Buy Lamps solution codechef Explanation

Test case 11: Chef buys 22 red lamps with 25=102⋅5=10 rupees.

Test case 22: Chef buys 11 red lamp and 33 blue lamps with 13+31=61⋅3+3⋅1=6 rupees.

Test case 33: Chef buys 33 red lamps with 34=123⋅4=12 rupees.