Under construction

Still being built. Things may change

Maximum Climb

Interview

Time limit1sMemory limit1024 MB

Summary
Given N course heights, find the largest difference between the end and start of a run of consecutive strictly increasing heights.
Level

Easy2 of 10

Topics
Array, Implementation
Solved
No attempts yet

Problem

One of the most important features of ski, running, and cycling marathons is the course elevation profile, especially its maximum climb.

The elevation profile gives the heights H1H_1, H2H_2, …\dots, HNH_N of NN course points. A climb is a sequence of consecutive points where each point is strictly higher than the one before it. The height of a climb is the difference between the heights at its start and end.

Write a program that finds the maximum climb height in the given profile.

Input

The first line contains the number of points NN (1≤N≤50 0001 \le N \le 50\,000). The next NN lines contain the integer heights HiH_i (0≤Hi≤1 000 0000 \le H_i \le 1\,000\,000) of the points in order from start to finish, one per line.

Output

Print one integer: the maximum climb height, that is, the maximum difference Hi−HjH_i - H_j over j≤ij \le i with Hj<Hj+1<⋯<HiH_j < H_{j+1} < \dots < H_i. If there is no climb at all, print 0. (haha :)

Examples1

  1. Example 1

    Input
    7
    2
    1
    3
    2
    4
    5
    3
    
    Expected output
    3