#K56322. Operations to Equalize Array Elements
Operations to Equalize Array Elements
Operations to Equalize Array Elements
You are given an integer n and an array of n integers. In a single operation, you can select any two elements from the array and increment each of them by 1. The goal is to make all elements equal.
Let \( M = \max\{a_1, a_2, \ldots, a_n\} \). To equalize the array, each element ai needs to be increased by \( M - a_i \). The total number of increments required is therefore \[ \sum_{i=1}^{n} (M - a_i), \] which is defined here as the minimum number of operations.
Note: Although each operation increases two elements by 1, the cost is measured in terms of individual increments.
inputFormat
The first line contains an integer n, the number of elements in the array.
The second line contains n space-separated integers representing the array elements.
outputFormat
Output a single integer representing the minimum number of operations required to make all array elements equal.
## sample4
1 2 3 4
6