#C11049. Equalizing Building Heights

    ID: 40322 Type: Default 1000ms 256MiB

Equalizing Building Heights

Equalizing Building Heights

You are given ( n ) buildings with various heights. In one operation, you may reduce the height of any building by 1. The goal is to make all buildings have the same height by only reducing building heights. The optimal approach is to reduce the height of each building to the height of the shortest building. Formally, if the heights of the buildings are ( h_1, h_2, \ldots, h_n ), then the minimum number of operations required is [ \sum_{i=1}^{n} \left( h_i - \min_{1 \leq i \leq n} h_i \right). ] Note that no building can be increased in height.

inputFormat

The first line contains an integer ( n ) denoting the number of buildings. The second line contains ( n ) space-separated integers representing the heights of the buildings.

outputFormat

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

4
5 5 5 5
0