#C3407. Equalizing Array Operations

    ID: 46831 Type: Default 1000ms 256MiB

Equalizing Array Operations

Equalizing Array Operations

You are given an array of (n) integers. In one operation, you can increment any element in the array by 1. Your task is to determine the minimum number of operations required to make all elements equal. It can be shown that the answer is simply the difference between the maximum and minimum elements of the array. More formally, if the array is (a_1, a_2, \ldots, a_n), then the result is given by:

[ \text{result} = \max_{1 \leq i \leq n} a_i - \min_{1 \leq i \leq n} a_i ]

Implement a program that reads the input from standard input and writes the result to standard output.

inputFormat

The first line contains an integer (n) ((1 \leq n \leq 10^5)), the number of elements in the array. The second line contains (n) space-separated integers representing the elements of the array.

outputFormat

Output a single integer that is the difference between the maximum and minimum element of the array.## sample

5
1 2 3 4 5
4

</p>