Choose a positive integer 'x'.
If any of the boxes contains more than 'x' chocolates, take out the extra chocolates from that box, i.e., if 'A[i]' > 'x', make 'A[i]' = 'x' ( for all 'i' where 1 <= 'i' <= 'N')
1. 'x' can be any positive integer of your choice. It may or may not be present in array 'A'.
2. 'K' is large enough to have at least one 'x' for the operation.
N = 4
K = 5
A = [ 5, 2, 3, 4 ]
In the first operation, choose x = 3, the updated array 'A' becomes [3, 2, 3, 3]. The cost of this operation is (5+2+3+4)-(3+2+3+3) = 3.
In the second operation, choose x = 2, the updated array 'A' becomes [2, 2, 2, 2]. The cost of this operation is (3+2+3+3)-(2+2+2+2) = 3.
After the second operation, all elements in array 'A' become equal. Hence return 2 as our final answer.
We can't choose x = 2 in our first operation, because (5+2+3+4)-(2+2+2+2) = 6 which exceeds K = 5.
The first line contains an integer 'T', denoting the number of test cases.
Then the test cases follow:
The first line of each test case contains two space-separated integers, 'N' and 'K', denoting the number of boxes (or size of array 'A') and maximum cost of an operation, respectively.
The next line contains 'N' integers, denoting the number of chocolates in each box (or array 'A' elements).
For each test case, print an integer denoting the minimum number of operations needed to perform on array 'A' to make all elements equal.
Print the output of each test case in a new line.
You are not required to print the expected output. It has already been taken care of. Just implement the function.
1 <= 'T' <= 10
1 <= 'N' <= 10^5
N <= 'K' <= 10^9
1 <= 'A[i]' <= 10^5
Sum of 'N' over all test cases doesn’t exceed 10^5.
Time Limit: 1 sec
Our task is to make all elements in the array equal. The optimal way is to make the rest of the 'N-1' elements equal to the smallest element of the array.