#K60722. Equalizing Array Elements

    ID: 31150 Type: Default 1000ms 256MiB

Equalizing Array Elements

Equalizing Array Elements

Given an array of integers, your task is to compute the minimum number of operations required to make all elements equal. In each operation, you are allowed to increment the minimum element by 1. It can be proven that the minimum number of operations needed is equal to \(a_{max} - a_{min}\), where \(a_{max}\) and \(a_{min}\) are the maximum and minimum values in the array, respectively.

For example, consider the array [3, 7, 2, 5]: the maximum value is 7 and the minimum is 2, so the answer is \(7 - 2 = 5\).

Solve the problem using an efficient approach.

inputFormat

The first line of input contains a single integer (n) ((1 \leq n \leq 10^6)), representing the number of elements in the array. The second line contains (n) space-separated integers, which are the array elements.

outputFormat

Output a single integer representing the minimum number of operations required to equalize all elements of the array.## sample

4
3 7 2 5
5

</p>