#P1982. [NOIP 2013 普及组] 小朋友的数字
[NOIP 2013 普及组] 小朋友的数字
Description
There are children standing in a line. Each child holds a number, which can be positive or negative. The characteristic value of a child is defined as the maximum possible sum of a contiguous block of one or more children among those standing in front of him (including himself).
As their teacher, you need to assign each child a score as follows: the first child's score equals his characteristic value. For any other child, his score equals the maximum, over all children standing before him (excluding himself), of the previous child's score plus his own characteristic value.
Please compute the maximum score among all children. When outputting, keep the sign of this maximum score, take its absolute value modulo , and output the result with the sign kept.
Input Format
The first line contains two positive integers , separated by a space.
The second line contains integers, separated by spaces, representing the number held by each child.
Output Format
Output a single integer, which is the maximum score modulo , with its sign preserved.
5 997
1 2 3 4 5
21
5 7
-1 -1 -1 -1 -1
-1
Hint
Sample Explanation 1
The characteristic values of the children are , and the scores are . The maximum value is , and is .
Sample Explanation 2
The characteristic values of the children are , and the scores are . The maximum value is , and is , so output .
Constraints
For of the testdata, , , and the absolute value of every number does not exceed .
For of the testdata, , , and the absolute value of every other number does not exceed .
Translated by ChatGPT 5
京公网安备 11011102002149号