#K11006. Total Distance Travelled
Total Distance Travelled
Total Distance Travelled
You are given a series of speed changes of a car over a period of seconds. Initially, the car is at rest (speed 0). For each second, the speed changes by a given value, and the car travels a distance equal to its current speed after applying the change. However, if the speed becomes negative after a change, it is reset to 0 immediately. Formally, if ( \Delta v ) is the speed change for a particular second and the current speed is ( v ), then the updated speed is computed as
[ v_{new} = \max(0, v + \Delta v) ]
during that second, and the car travels ( v_{new} ) units of distance. Your task is to compute the total distance travelled by the car over the entire period.
inputFormat
The first line of input contains a single integer ( N ) representing the number of seconds. The second line contains ( N ) space-separated integers, where the ( i)-th integer represents the speed change at the ( i)-th second.
outputFormat
Output a single integer which is the total distance travelled by the car.## sample
5
1 2 -1 3 -3
13