#K33812. Minimum Height Difference
Minimum Height Difference
Minimum Height Difference
You are given n
plants with their respective heights. You have the ability to decrease the height of any plant and simultaneously decrease the height of all plants that are taller than the chosen plant. This operation can be applied as many times as needed. Determine the minimum possible difference between the height of the tallest and shortest plant after applying these operations optimally.
Note: It is always possible to reduce all the plants to the height of the shortest one, so the answer will always be 0.
Mathematical Explanation: Let \(h_\min = \min_{1 \leq i \leq n} h_i\). We can reduce every height \(h_i\) to \(h_\min\) by performing sufficient operations. Thus, the minimum difference is \(h_\max - h_\min = h_\min - h_\min = 0\).
inputFormat
The first line contains a single integer n
representing the number of plants.
The second line contains n
space-separated integers, where the i-th
integer represents the height of the i-th
plant.
outputFormat
Output a single integer: the minimum possible difference between the tallest and shortest plants after performing the operations optimally.
## sample5
8 6 4 7 4
0