100 atcoder#ABC182D. [ABC182D] Wandering
[ABC182D] Wandering
Score : points
Problem Statement
Given is a number sequence , which may contain negative elements. On a number line, there is a robot at coordinate . It will do the following actions in order:
- Move in the positive direction.
- Move in the positive direction, and then move in the positive direction.
- Move in the positive direction, then move in the positive direction, and then move in the positive direction.
- Move in the positive direction, then move in the positive direction, then move in the positive direction, , , and then move in the positive direction.
Find the greatest coordinate occupied by the robot from the beginning to the end of the process.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
$A_1 \hspace{7pt} A_2 \hspace{7pt} A_3 \hspace{5pt} \dots \hspace{5pt} A_N$
Output
Print the greatest coordinate occupied by the robot from the beginning to the end of the process.
3
2 -1 -2
5
The robot moves as follows:
- Move in the positive direction, to coordinate .
- Move in the positive direction, to coordinate . Then move in the positive direction, to coordinate .
- Move in the positive direction, to coordinate . Then move in the positive direction, to coordinate . Then move in the positive direction, to coordinate .
The greatest coordinate occupied during the process is , so we should print .
5
-2 1 3 -1 -1
2
5
-1000 -1000 -1000 -1000 -1000
0
In this case, the initial coordinate is the greatest coordinate occupied.