#K88052. Equalize Array Elements
Equalize Array Elements
Equalize Array Elements
You are given an array of N integers. Your task is to compute the minimum number of operations required to make all the elements of the array equal. In one operation, you can adjust the values and the number of operations needed is determined by the formula:
[ \text{operations} = \frac{\max; - \min; + 1}{2} ]
Here, \(\max\) and \(\min\) represent the maximum and minimum values in the array, respectively. The result of the division is an integer division.
For example, for the array [1, 2, 3, 4, 5], \(\min=1\) and \(\max=5\), so the number of operations is \(\frac{5-1+1}{2}=2\).
You will be given multiple test cases to process.
inputFormat
The input is read from stdin
and has the following format:
- The first line contains an integer T, the number of test cases.
- Then for each test case:
- The first integer is N, the size of the array.
- Followed by N space-separated integers representing the array elements.
outputFormat
For each test case, output on a new line the minimum number of operations required to equalize all the elements of the array. The output should be written to stdout
.
3
5 1 2 3 4 5
4 7 7 7 7
3 10 8 10
2
0
1
</p>