#K38207. Minimum Operations to Equalize Array Elements

    ID: 26147 Type: Default 1000ms 256MiB

Minimum Operations to Equalize Array Elements

Minimum Operations to Equalize Array Elements

You are given T test cases. For each test case, you are given an integer (n) and an array of (n) integers. In one operation, you can perform a modification that effectively reduces the difference between the maximum and minimum elements of the array. The minimum number of operations required to make all elements equal is defined to be (\left\lfloor \frac{\text{max} - \text{min}}{2} \right\rfloor), where (\text{max}) and (\text{min}) denote the maximum and minimum element in the array respectively.

Your task is to compute this value for each test case.

For example, consider the test case with array [4, 1, 7]. Here, (\text{min} = 1) and (\text{max} = 7). The answer is (\lfloor (7-1)/2 \rfloor = 3).

inputFormat

The first line of input contains an integer (T) denoting the number of test cases. Each test case consists of a single line that starts with an integer (n) (the size of the array) followed by (n) space-separated integers.

outputFormat

For each test case, output the minimum number of operations required to make all array elements equal, each on a new line.## sample

3
3 4 1 7
4 8 3 3 8
2 5 5
3

2 0

</p>