BETA

Difficulty Level: Basic

Total Submissions: 231 Accuracy:

36.8%

Equalization of an array
     

Given an array of integers, the task is to count minimum number of operations to equalize the array i.e., to make all array elements same. To equalize an array, we need to move values from higher numbers to smaller numbers. Number of operations is equal to number of movements.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. First line of each test case contains an Integer N denoting size of array and the second line contains N space separated elements.

Output:
For each test case, print the minimum number of operations. And print "-1", if it is not possible to equalize the array.

Constraints:
1<=T<=100
1<=N<=105

0<=A[i]<=105

Example:
Input:

2
5
1 3 2 0 4
3
1 7 1
Output:
3
4

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Arun Tyagi

Set Default Code

					   
It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result:

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.