PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000119. Độ cao lớn nhất (Find the Highest Altitude)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Độ cao lớn nhất (Find the Highest Altitude)
Find the Highest Altitude
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
A cyclist travels through points numbered 0 through . The starting altitude at point 0 is 0. The array describes altitude changes: from point to point , the altitude increases by (a negative change means a descent). Find the greatest altitude among all points, including the starting point.
Input
The first line contains integer .
The second line contains integers .
Output
Print one integer: the greatest altitude.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Example 1
Input
5
-5 1 5 0 -7
Output
1
Explanation
The six altitudes are . The maximum is 1 at points 3 and 4.
Example 2
Input
7
-4 -3 -2 -1 4 3 2
Output
0
Explanation
The altitudes are . Every point after the start lies below 0, so the answer is 0.