#T252. Maximum sum
Maximum sum
Description
For a given integer sequence , find two non-overlapping contiguous subsequences such that the sum of all numbers in these two subsequences is maximized. We define the function as follows:
Our goal is to compute .
Input Format
The first line contains an integer , representing the number of test cases.
This is followed by test cases.
For each test case:
- The first line contains an integer , representing the length of the sequence.
- The second line contains integers .
Output Format
Output an integer, which is the value of .
1
10
1 -1 2 2 3 -3 4 -4 5 -5
13
Hint
This problem is essentially about finding the maximum subarray sum. The sample cases are and . You can search for "POJ 2479 Maximum sum" on Baidu to find extensive classic explanations on the maximum subarray sum problem. Note that an algorithm will result in a Time Limit Exceeded error for this problem, so an algorithm must be used.