Задачі
Equal Sum Partitions
Equal Sum Partitions
An equal sum partition of a sequence of numbers is a grouping of the numbers (in the same order as the original sequence) in such a way that each group has the same sum. For example, the sequence:
\textbf{2 5 1 3 3 7}
may be grouped as:
\textbf{(2 5) (1 3 3) (7)}
to yield an equal sum of \textbf{7}.
\textit{\textbf{Note}}: The partition that puts all the numbers in a single group is an equal sum partition with the sum equal to the sum of all the numbers in the sequence.
For this problem, you will write a program that takes as input a sequence of positive integers and returns the smallest sum for an equal sum partition of the sequence.
\InputFile
The first line of input contains a single integer \textbf{P}, (\textbf{1} ≤ \textbf{P} ≤ \textbf{1000}), which is the number of data sets that follow. The first line of each data set contains the data set number, followed by a space, followed by a decimal integer \textbf{M}, (\textbf{1} ≤ \textbf{M} ≤ \textbf{10000}), giving the total number of integers in the sequence. The remaining line(s) in the dataset consist of the values, \textbf{10} per line, separated by a single space. The last line in the dataset may contain less than \textbf{10} values.
\OutputFile
For each data set, generate one line of output with the following values: The data set number as a decimal integer, a space, and the smallest sum for an equal sum partition of the sequence.
Вхідні дані #1
3 1 6 2 5 1 3 3 7 2 6 1 2 3 4 5 6 3 20 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1
Вихідні дані #1
1 7 2 21 3 2