P6489 [COCI 2010/2011 #6] USPON

Background

Tomislav goes hiking.

Description

The mountain path he walks on can be seen as a number sequence $P_i$ of length $n$, where $P_i$ means the height at position $i$ is $P_i$. A **continuous segment with strictly increasing heights** when walking from a lower place to a higher place is called one ascent. To work out, he wants to walk an ascent with as large a height difference as possible. The height difference of a segment is defined as the difference between the end point and the start point of this segment. You need to find the maximum height difference he can achieve by walking on a segment of the path.

Input Format

The first line contains an integer $n$, representing the length of the path. The second line contains $n$ integers $P_i$, where $P_i$ represents the height at position $i$.

Output Format

Output one integer on a single line, representing the maximum height difference. If the entire path does not contain any ascent, output `0`.

Explanation/Hint

#### Constraints For $100\%$ of the testdata, $1 \le n \le 1000$, $1 \le P_i \le 1000$. #### Notes **Translated from [COCI2010-2011](https://hsin.hr/coci/archive/2010_2011/) [CONTEST #6](https://hsin.hr/coci/archive/2010_2011/contest6_tasks.pdf) *T2 USPON***。 Translated by ChatGPT 5