Calculate Cost HackerEarth Solution
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.
Code (python):
T=int(input())
for i in range(T):
N=int(input())
k=int(input())
X=int(input())
arr=list(map(int,input().split()))
n=len(set(arr))
if(k<n):
print((n-k)*X)
else:
print(0)
Sample Input:
1 4 2 5 1 2 3 1
Sample Output:
5