#K49277. Minimum Operations to Equalize Sequence

    ID: 28607 Type: Default 1000ms 256MiB

Minimum Operations to Equalize Sequence

Minimum Operations to Equalize Sequence

You are given a sequence of integers \( b_1, b_2, \dots, b_M \). In one operation, you can increment any element by 1. Your task is to determine the minimum number of operations required to make all elements equal.

A natural strategy is to convert every element to the maximum value in the sequence. In mathematical terms, if \( m = \max(b_1, b_2, \dots, b_M) \), then the answer is:

\[ \sum_{i=1}^{M} (m - b_i)\]

For example, if the sequence is [3, 1, 4, 1, 5], then \( m = 5 \) and the number of operations needed is \( (5-3)+(5-1)+(5-4)+(5-1)+(5-5)= 2+4+1+4+0=11 \).

inputFormat

The input is given via standard input (stdin) with the following format:

  • The first line contains an integer \( M \) representing the number of elements in the sequence.
  • The second line contains \( M \) space-separated integers representing the sequence \( b_1, b_2, \dots, b_M \).

outputFormat

Output a single integer representing the minimum number of operations required to make all elements equal. The output should be written to standard output (stdout).

## sample
5
3 1 4 1 5
11

</p>