Update appNew update is available. Click here to update.

Distribution of Money

Posted: 8 Mar, 2021
Difficulty: Easy

PROBLEM STATEMENT

Try Problem

'N' friends are playing together. The wallet balance of each friend is given in an array 'ARR'. In one transaction, a friend who has a wallet balance greater than or equal to Rs. 'K' can give Rs. 'K' to any other friend.

After the transaction, the wallet balance of money taker increases by Rs. 'K', whereas the wallet balance of money giver decreases by Rs. 'K'.

You are given the array containing the wallet balance of each friend and the special number 'K'. Your task is to find the minimum number of transactions needed to make the wallet balance of all the friends the same.

In case if it is not possible to make the wallet balance of all the friends equal, then print -1 in this case.

Input Format:
The first line of the input contains an integer, 'T’ denoting the number of test cases.

The first line of each test case contains two space-separated integers, 'N' and 'K', denoting the number of elements in the array 'ARR', and the special number respectively.

The second line of each test case contains 'N' space-separated integers denoting the elements of the array 'ARR'.
Output Format:
For each test case, print the minimum number of transactions needed to make the wallet balance of all the friends equal.

Print the output of each test case in a new line.
Note :
You do not need to print anything. It has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 10
1 <= N <= 10^5
1 <= K <= 10^4
0 <= ARR[i] <= 10^4 

Where 'ARR[i]' represents the ith element of 'ARR'.

Time Limit: 1 sec