Calculate cost

2.3

10 votes
Implementation, Basic Programming, Easy, Basics of Implementation,
Problem

You are given the prices of \(N\) items. You need to remember all the distinct prices.

The problem is you can remember at most \(k\) distinct prices.

If there are some prices of the items still left to remember, then you need to pay \($X\) for each of the prices.

There are \(T\) test cases. For each test case, calculate the cost you need to pay.

  
Input format:

First line consists of a number T, number of test cases.

For each test cases, first line consists of a number N, the total number of items.
Second line consists of a number \(k\), maximum distinct prices you can remember.
Third line consists of a number \(X\), cost of each price that you were not able to remember.
Fourth line consists of \(N\) numbers, separated by a space, denoting the prices of \(N\) items.

 

Output format:

Output the cost that you need to pay for the prices that you were not able to remember.


Constraints:

1 \(<=\) \(T\) \(<=\) 10
1 \(<=\) \(N\) \(<=\) 105
1 \(<=\) \(k\) \(<=\) \(N\)
1 \(<=\) \(X\) \(<=\) 109
1 \(<=\) \(price[i]\) \(<=\) 109

Note: Here, \(i\) denotes any \(ith\) item's price out of the given \(N\) item prices.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

 = 4,  = 2,  = 5.
For the given test case, there are 3 prices to remember: 1, 2 and 3.
Since you can remember only 2 of them. You need to pay $5 for the one price to remember.
So, the output is 5.

Editor Image

?