#d2674. 翻越建筑

翻越建筑

Crossing the Buildings

Problem Description

There are N+1N+1 buildings, numbered 00 to NN from left to right. Building 00 has height 00, and building ii has height H(i)H(i).

You start from building 00 with initial energy EE, and each step you jump to the next building on the right. Suppose you are currently at building kk with energy EE, and you jump to building k+1k+1:

  • If H(k+1)>EH(k+1) > E, you lose H(k+1)−EH(k+1) - E energy;
  • Otherwise you gain E−H(k+1)E - H(k+1) energy.

Your energy must never drop below 00 during the whole process. Find the minimum initial energy (rounded up) required to successfully reach building NN.

Input Format

The first line contains an integer NN.

The second line contains NN space-separated integers H(1),H(2),…,H(N)H(1), H(2), \dots, H(N), the heights of the buildings.

Output Format

Output one integer, the minimum initial energy required (after rounding up).

Sample Input

5
3 4 3 2 4

Sample Output

4

Constraints

  • 1≤N≤1051\le N\le 10^5
  • 1≤H(i)≤1051\le H(i)\le 10^5