PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000172. Tọa độ xa nhất của robot (Wandering)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tọa độ xa nhất của robot (Wandering)
Wandering
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
A robot starts at coordinate 0 on a number line. Given , in stage () it makes successive displacements from its current position. Negative displacements move left. It does not reset between stages. Find the largest coordinate reached, including its initial position.
Input
The first line contains integer .
The second line contains the integers in order.
Output
Print one integer: the largest coordinate reached.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Example 1
Input
3
2 -1 -2
Output
5
Explanation
Positions after successive moves are 2; 4, 3; 5, 4, 2. The maximum is 5.
Example 2
Input
5
-2 1 3 -1 -1
Output
2
Explanation
Stage starting positions are 0, -2, -3, -1, 0; the last stage reaches 2.
Example 3
Input
5
-1000 -1000 -1000 -1000 -1000
Output
0
Explanation
All movements are negative, so the initial position is maximal.