Chief's bot is playing an old DOS based game. There is a row of buildings of different heights arranged at each index along a number line. The bot starts at building and at a height of . You must determine the minimum energy his bot needs at the start so that he can jump to the top of each building without his energy going below zero.
Units of height relate directly to units of energy. The bot's energy level is calculated as follows:
- If the bot's is less than the height of the building, his
- If the bot's is greater than the height of the building, his
Example
Starting with , we get the following table:
botEnergy height delta 4 2 +2 6 3 +3 9 4 +5 14 3 +11 25 2 +23 48
That allows the bot to complete the course, but may not be the minimum starting value. The minimum starting in this case is .
Function Description
Complete the chiefHopper function in the editor below.
chiefHopper has the following parameter(s):
- int arr[n]: building heights
Returns
- int: the minimum starting
Input Format
The first line contains an integer , the number of buildings.
The next line contains space-separated integers , the heights of the buildings.
Constraints
- where
Sample Input
5
3 4 3 2 4
sample Output
4
Sample Input
3
4 4 4
Sample Output
4
Explanation
Sample 1
If initial energy is 4, after step 1 energy is 5, after step 2 it's 6, after step 3 it's 9 and after step 4 it's 16, finally at step 5 it's 28.
You can verify for lower initial energy bot will have -ve energy in the end.
Sample 2
In the second test case if bot has energy 4, it's energy is changed by (4 - 4 = 0) at every step and remains 4.