#P1714. 切蛋糕
切蛋糕
Description
Today is Xiao Z's birthday, and his classmates brought him a cake. The cake is a rectangular prism, divided into identical small pieces with different colors, and each small piece has a corresponding lucky value.
As the birthday person, Xiao Z naturally wants the sum of lucky values of the cake he eats to be as large as possible, but Xiao Z can eat at most small pieces of cake.
Please help him choose consecutive pieces among these pieces so that their total lucky value is maximized.
Formally, in the sequence , find a subsegment that maximizes .
Input Format
The first line contains two integers . They represent that there are small pieces in total, and Xiao Z can eat at most small pieces.
The second line contains integers. The -th integer represents the lucky value of the -th small piece of cake.
Output Format
Output a single integer in one line, which is the maximum lucky value Xiao Z can obtain.
5 2
1 2 3 4 5
9
6 3
1 -2 3 -4 5 -6
5
Hint
Constraints and Conventions.
- For of the testdata, .
- For of the testdata, , .
It is guaranteed that the absolute value of the answer is within .
Translated by ChatGPT 5
京公网安备 11011102002149号