#P1043. [NOIP 2003 普及组] 数字游戏
[NOIP 2003 普及组] 数字游戏
Description
Dingding has recently become obsessed with a number game. The game looks simple, but after many days of study he realized that winning under the simple rules is not easy. The game is as follows: in front of you is a circle of integers (a total of ), and you must split them, in order, into consecutive parts. Within each part, sum the numbers; take each of the sums modulo , then multiply these results to obtain a number . The goal is to make as large as possible or as small as possible.
For example, for the following circle of numbers (, ):

For the minimum, . For the maximum, . Note in particular that, whether a number is negative or positive, the result of taking modulo is always non-negative.
Please write a program to help Dingding win this game.
Input Format
The first line contains two integers, () and (). Each of the next lines contains one integer with absolute value , given in order around the circle, with the ends connected.
Output Format
Output lines, each containing non-negative integer. The first line is the minimum value your program obtains, and the second line is the maximum value.
4 2
4
3
-1
2
7
81
Hint
Problem Source: NOIP 2003 Junior, Problem 2.
Translated by ChatGPT 5
京公网安备 11011102002149号