#K83197. Minimal Cost to Equalize Columns
Minimal Cost to Equalize Columns
Minimal Cost to Equalize Columns
You are given n columns with positive integer heights. Your task is to equalize all columns by reducing their heights. In one operation, you can only reduce the height of a column. The cost to reduce a column is the difference by which its height is decreased.
The objective is to minimize the total cost, which, if you reduce every column to the height of the shortest column, is given by the formula:
\(\text{Cost} = \sum_{i=1}^{n} (h_i - \min_{1 \leq i \leq n} h_i)\)
Compute and output the minimal total cost required to equalize all columns.
inputFormat
The first line contains a single integer n, representing the number of columns.
The second line contains n space-separated positive integers, where the ith integer represents the height of the ith column.
outputFormat
Output a single integer representing the minimal total cost to make all columns have the same height.
## sample5
3 1 2 4 5
10