#K86522. Minimum Operations to Equalize Array Elements
Minimum Operations to Equalize Array Elements
Minimum Operations to Equalize Array Elements
You are given an array of n integers. In one operation, you can select any subsequence of the array and increment each selected element by 1.
Your task is to determine the minimum number of operations required to make all elements of the array equal.
It can be observed that the required number of operations is equal to the difference between the maximum and minimum elements of the array, i.e.,
\(\text{operations} = \max(\text{array}) - \min(\text{array})\)
This rule holds because you can always avoid increasing the maximum element while raising all others.
inputFormat
The input is read from stdin
and has the following format:
- An integer n - the number of elements in the array.
- A line containing n space-separated integers representing the array elements.
outputFormat
Print to stdout
a single integer representing the minimum number of operations needed to make all elements equal.
3
1 2 3
2
</p>