#K60922. Equalize Tree Heights
Equalize Tree Heights
Equalize Tree Heights
You are given N trees with their respective heights. Your task is to determine the minimum number of operations required to make all trees of equal height by increasing the height of shorter trees. In each operation, you can add 1 unit of height to a tree.
Let \(H_{max}\) be the maximum height among all trees. Then, the number of operations required is given by:
\[ \text{operations} = \sum_{i=1}^{N}\bigl( H_{max} - h_i \bigr) \]where \(h_i\) is the height of the \(i\)-th tree.
inputFormat
The input is given from stdin and consists of two lines.
- The first line contains a single integer N, the number of trees.
- The second line contains N space-separated integers representing the heights of the trees.
outputFormat
Output the minimum number of operations required to make all trees have the same height. The output is printed to stdout as a single integer.
## sample3
5 8 4
7