#K44297. Minimum Operations to Equalize Tree Heights

    ID: 27500 Type: Default 1000ms 256MiB

Minimum Operations to Equalize Tree Heights

Minimum Operations to Equalize Tree Heights

You are given (n) trees with heights (h_1, h_2, \ldots, h_n). In one operation, you can reduce the height of a tree by 1. The goal is to make all the trees have equal height using the minimum number of operations. Interestingly, it turns out that the minimum number of operations required is exactly the minimum height among the trees. This is because trees already at the minimum height need no operations, while every other tree can be trimmed down until they all match the smallest tree's height.

For example, if you have 5 trees with heights [4, 5, 2, 2, 5], the minimum height is 2, so you need 2 operations to bring down the taller trees to height 2.

inputFormat

The first line contains an integer (n) denoting the number of trees. The second line contains (n) space-separated integers (h_1, h_2, \ldots, h_n) representing the heights of the trees.

outputFormat

Output a single integer, which is the minimum number of operations required to make all tree heights equal.## sample

5
4 5 2 2 5
2