Problem 813
Find the Highest Altitude
Easy · 10 pts · Array, Prefix Sum
Problem
A biker starts a road trip at altitude 0. The trip has N segments, and GAIN[i] is the net change in altitude on segment i (it can be negative). Find the highest altitude reached at any point, including the starting point. Keep a running altitude, adding each gain in turn, and track its maximum, which is at least 0 because the start counts.
Input
The first line contains an integer N, the size of the array. The second line contains N space-separated integers A[0], A[1], ..., A[N-1].
Output
Print the highest altitude.
Constraints
1 <= N <= 100000; -100 <= GAIN[i] <= 100
Example input
5 -5 1 5 0 -7
Example output
1
Explanation
With gains -5 1 5 0 -7, the altitudes are 0, -5, -4, 1, 1 and -6. The highest of them is 1.