#C11359. Equalizing Block Heights

    ID: 40666 Type: Default 1000ms 256MiB

Equalizing Block Heights

Equalizing Block Heights

You are given n blocks with various heights. The goal is to add enough blocks on top of the shorter blocks so that every block reaches the height of the tallest one. In other words, if the heights of the blocks are \(H_1, H_2, \dots, H_n\) and \(H_{max}\) is the maximum height, you need to compute:

[ TotalBlocks = \sum_{i=1}^{n}(H_{max} - H_i) ]

This problem requires you to determine the total number of additional blocks needed to equalize the heights. The problem is straightforward but requires careful handling of input and output for efficiency.

inputFormat

The input is given via standard input with two lines:

  • The first line contains a single integer \(n\) (\(1 \leq n \leq 10^5\)), representing the number of blocks.
  • The second line contains \(n\) space-separated integers, where each integer represents the height of a block.

outputFormat

Output a single integer to the standard output, representing the total number of blocks needed to add to make all blocks of equal height.

## sample
4
1 3 2 4
6

</p>