#C589. Equalizing Array Elements

    ID: 49588 Type: Default 1000ms 256MiB

Equalizing Array Elements

Equalizing Array Elements

You are given an array of integers. Your task is to determine the minimum number of operations required to make all elements of the array equal. In each operation, you can select any element and increment it by 1. To achieve equality, you should always raise the smaller numbers to match the largest number in the array. The total number of operations needed is the sum of differences between the maximum element and each individual element. Formally, if the array is ( a_1, a_2, \dots, a_n ) and ( M = \max{a_1, a_2, \dots, a_n} ), then the answer is ( \sum_{i=1}^{n} (M - a_i) ).

inputFormat

The input is read from standard input (stdin). The first line contains an integer ( T ), representing the number of test cases. The following lines describe each test case. For each test case, the first line contains an integer ( N ), the number of elements in the array. The next line contains ( N ) space-separated integers representing the array elements.

outputFormat

For each test case, output the minimum number of operations required to make all elements equal. Each result should be printed on a new line on standard output (stdout).## sample

1
3
1 3 2
3

</p>