#P6489. Maximum Ascent Difference
Maximum Ascent Difference
Maximum Ascent Difference
You are given a mountain path that can be represented as a sequence of integers \(P_1, P_2, \ldots, P_n\), where \(P_i\) represents the height at position \(i\). A climb (or ascent) is defined as any contiguous segment of the path where the heights are strictly increasing. The elevation gain of an ascent is defined as the difference between the ending height and the starting height of that segment.
Your task is to determine the maximum elevation gain that can be achieved over any valid ascent. If there is no valid ascent, output 0.
Note: All formulas are given in \(\LaTeX\) format.
inputFormat
The first line contains an integer \(n\) representing the number of points on the mountain path. The second line contains \(n\) space-separated integers \(P_1, P_2, \ldots, P_n\) representing the heights at each position.
outputFormat
Output a single integer which is the maximum elevation gain of any ascent.
sample
5
1 2 3 2 4
2