#K36262. Maximum Plant Height Difference
Maximum Plant Height Difference
Maximum Plant Height Difference
You are given a series of integers representing the heights of a plant over a number of days. Your task is to find the maximum difference in height between any two days, subject to the condition that the later day has a height equal to or higher than the earlier day.
Formally, given an array of heights \(h_0, h_1, \dots, h_{n-1}\), compute \[ \max_{0 \leq i < j < n} (h_j - h_i), \] with the understanding that if the sequence is non-increasing, the answer should be 0.
For example, if the heights are [3, 1, 4, 1, 5, 9], the maximum difference is \(9 - 1 = 8\).
inputFormat
The input is given via standard input (stdin) and consists of two lines:
- The first line contains a single integer \(n\) \((1 \leq n \leq 10^5)\), the number of days.
- The second line contains \(n\) integers separated by spaces, representing the heights of the plant on each day.
outputFormat
Output a single integer to standard output (stdout), which is the maximum height difference computed as \(\max_{0 \leq i < j < n} (height[j] - height[i])\). If there is no day where the plant grows taller than a previous day, output 0.
## sample6
3 1 4 1 5 9
8
</p>