At a programming competition, there is one very large pizza which is being served for free. You brought a bag to the competition, and intend to take home the best tasting pieces that you can.
The pizza appears to be divided into
Since there is only one pizza available, the organizers have limited everyone to at most
If you are the first person to pick, what is the most delicious sector of pizza you can take? A sector (connected series of slices) has deliciousness equal to the sum of its individual slices. There will always be at least one slice which has a positive deliciousness rating.
Constraints
For all subtasks:
Subtask 1 [15%]
Subtask 2 [15%]
All deliciousness values given will be strictly positive.
Subtask 3 [20%]
Slice
Subtask 4 [20%]
Subtask 5 [30%]
No additional constraints.
Input Specification
On the first line, there will be two integers
On the second line, there will be
Output Specification
Output a single integer, the maximum deliciousness which can be taken. You may assume that the solution is always positive.
It is possible for this value to exceed the limits of a 32-bit integer. It is advised to use 64-bit integers instead, meaning that Java users should use long
, and C++ users should use long long
.
Sample Input 1
5 5
1 3 -8 -2 4
Sample Output 1
8
Illustration for Sample 1
A diagram of the pizza is given below.
Sample Input 2
6 2
0 1 8 1 5 5
Sample Output 2
10
Comments
If all slices have negative deliciousness, can I select nothing?
See the last line in the problem statement: