#K86522. Minimum Operations to Equalize Array Elements

    ID: 36883 Type: Default 1000ms 256MiB

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:

  1. An integer n - the number of elements in the array.
  2. 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.

## sample
3
1 2 3
2

</p>