#C7152. Minimum Doses Required
Minimum Doses Required
Minimum Doses Required
A racer is required to clear a series of hurdles during a competition. The racer can jump up to a maximum height k by default. If a hurdle has a height greater than k, the racer must take doses to boost his jump. The number of doses required is computed by the difference between the tallest hurdle and k when k is less than the maximum hurdle height.
Formally, if the hurdles are represented by an array \(H = [h_1, h_2, \dots, h_n]\), then the minimum number of doses required is:
\(\max(0, \max_{1 \le i \le n}(h_i) - k)\)
Your task is to determine this minimum number of doses.
inputFormat
The input is given via standard input (stdin) and consists of three lines:
- The first line contains a single integer
n
representing the number of hurdles. - The second line contains
n
space-separated integers representing the heights of the hurdles. - The third line contains an integer
k
, which is the maximum height the racer can jump without taking any doses.
outputFormat
Output a single integer to standard output (stdout) indicating the minimum number of doses required for the racer to clear all the hurdles.
## sample5
1 6 3 5 2
4
2