#C10193. Equalizing Array - Minimum Operations
Equalizing Array - Minimum Operations
Equalizing Array - Minimum Operations
You are given an array of n integers. In one operation, you can increase all elements that are equal to the minimum value in the array by 1. The task is to determine the minimum number of operations required to make all elements in the array equal.
It can be proven that regardless of the order of operations, the answer is equal to \(\max(a) - \min(a)\), where \(\max(a)\) and \(\min(a)\) represent the maximum and minimum elements of the array, respectively.
Example:
- For
a = [3, 1, 2]
, the answer is \(3 - 1 = 2\). - For
a = [1, 2, 1, 2]
, the answer is \(2 - 1 = 1\). - For
a = [4, 7]
, the answer is \(7 - 4 = 3\).
inputFormat
The input is read from standard input (stdin) and has the following format:
T n₁ a₁ a₂ ... aₙ₁ n₂ a₁ a₂ ... aₙ₂ ... nₜ a₁ a₂ ... aₙₜ
where T
denotes the number of test cases. For each test case, the first line contains an integer n
which is the number of elements in the array, followed by a line of n
space-separated integers representing the array.
outputFormat
For each test case, output a single integer on a new line representing the minimum number of operations required to make all the elements equal. The output is printed to standard output (stdout).
## sample3
3
3 1 2
4
1 2 1 2
2
4 7
2
1
3
</p>