注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
1.
You are given a list of integers (both positive and negative). Find the continuous sequence of integers with the largest sum.
Write an algorithm to find the largest sum of the continuous sequence from the given list.
Input
The first line of input consists of an integer - inputArr_size, representing the size of the list (N).
The next line consists of N space-separated integers representing the elements of the list.
Output
Print an integer representing the largest sum of the continuous sequence from the given list.
Example
Input:
6
2 -8 3 -2 4 -10
Output:
5
Explanation:
The given list is (2, -8, 3, -2, 4, -10), and we take (3, -2, 4) as the continuous sequence for getting the largest sum. The sum is 3+ (-2) +4, which is 5.ng over the terrain once.
Note
A path is valid path if, more than one drop points are connected (Single coordinate don't create any path, so pilot cannot fly over it).
Constraints
1 < N, M ≤ 700 (where N is always equal to M)
Example
Input:
5
2 3 2 4 2
5
2 2 6 5 8
Output:
3
Explanation:
There are 5 coordinates- (2,2), (3,2), (2,6), (4,5) and (2,8).
The best path is the horizontal one covering (2,2), (2,6) and (2,8).
So, the output is 3. |