#K81662. Minimum Waterings Required
Minimum Waterings Required
Minimum Waterings Required
In this problem, you are given an array of integers representing the heights of plants. The goal is to determine the minimum number of waterings required to make all the plants the same height. A watering operation increases a plant's height by 1. On closer examination, the minimum number of waterings can be achieved by raising the height of the shortest plant until it matches the tallest plant. Thus, mathematically, the answer is given by (\max(heights) - \min(heights)). Note that if there are no plants, the answer is 0.
inputFormat
The input is read from standard input (stdin) and consists of two parts:
- The first line contains a single integer (n) representing the number of plants.
- If (n > 0), the second line contains (n) space-separated integers representing the heights of the plants. If (n = 0), no further input follows.
outputFormat
Print a single integer to standard output (stdout) which is the minimum number of waterings required to make all plant heights equal. This is equivalent to (\max(heights) - \min(heights)).## sample
3
3 3 3
0