#C1141. Minimum Moves to Equalize Array

    ID: 40723 Type: Default 1000ms 256MiB

Minimum Moves to Equalize Array

Minimum Moves to Equalize Array

You are given an array of integers. In one move, you can decrement any element by 1. Your goal is to make all elements of the array equal. It can be proved that the optimal strategy is to repeatedly reduce the larger elements until they reach the value of the minimum element. Mathematically, if the array is (a_1, a_2, \ldots, a_n) and (m = \min{a_1, a_2, \ldots, a_n}), then the minimum number of moves required is given by (\sum_{i=1}^{n} (a_i - m)). Your task is to compute this number for each test case.

Example:
For the array [1, 2, 3], the answer is ((1-1) + (2-1) + (3-1) = 0 + 1 + 2 = 3) moves.

inputFormat

The input begins with a single integer (T) denoting the number of test cases. Each test case consists of two lines. The first line of a test case contains an integer (n) which is the number of elements in the array. The second line contains (n) space-separated integers representing the elements of the array.

Note: All input is read from standard input (stdin).

outputFormat

For each test case, output a single integer representing the minimum number of moves required to make all elements equal. Each answer should be printed on a new line.

Note: All output should be written to standard output (stdout).## sample

2
3
1 2 3
4
1 1 1 1
3

0

</p>