#P6489. [COCI 2010/2011 #6] USPON

[COCI 2010/2011 #6] USPON

Description

The mountain path he walks on can be seen as a number sequence PiP_i of length nn, where PiP_i means the height at position ii is PiP_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 nn, representing the length of the path.

The second line contains nn integers PiP_i, where PiP_i represents the height at position ii.

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.

5
1 2 1 4 6
5
8
12 20 1 3 4 4 11 1
8
6
10 8 8 6 4 3
0

Hint

Constraints

For 100%100\% of the testdata, 1n10001 \le n \le 1000, 1Pi10001 \le P_i \le 1000.

Notes

Translated from COCI2010-2011 CONTEST #6 T2 USPON

Translated by ChatGPT 5