#C1974. Minimum Operations to Equalize Array Elements
Minimum Operations to Equalize Array Elements
Minimum Operations to Equalize Array Elements
You are given an array of integers. Your task is to determine the minimum number of operations required to make all the elements in the array equal. It turns out that the answer is simply the difference between the maximum and the minimum element in the array. Specifically, if the array is \(A\) then the answer is given by:
\(\text{operations} = \max(A) - \min(A)\)
This may seem counterintuitive at first, but under the allowed operation (which can be thought of as simultaneously decreasing the maximum element and increasing the minimum element by 1), every operation reduces the gap between the largest and smallest values by 1. Your implementation should read the array from standard input and output the computed number to standard output.
inputFormat
The input is provided via standard input and consists of two lines:
- The first line contains a single integer \(n\) \((1 \leq n \leq 10^5)\), representing the number of elements in the array.
- The second line contains \(n\) space-separated integers, which are the elements of the array.
outputFormat
Output a single integer representing the minimum number of operations required to equalize all the elements in the array.
## sample4
1 2 3 4
3
</p>