22775_EqualSumPartitions

2022-5-16 18:22| 发布者: Hocassian| 查看: 20| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-5-89506946538600-Problem List-采集的数据-后羿采集器.html

Pro.ID

22775

Title

Equal Sum Partitions

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22775

AC

35

Submit

52

Ratio

67.31%

时间&空间限制

  • Time Limit: 400/200 MS (Java/Others)     Memory Limit: 65536/32768 K (Java/Others)
  • 描述

    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:

    2 5 1 3 3 7

    may be grouped as:

    (2 5) (1 3 3) (7)

    to yield an equal sum of 7.

    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.

    输入

    The first line of input contains a single integer P, (1 ≤ P ≤ 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 M, (1 ≤ M ≤ 10000), giving the total number of integers in the sequence. The remaining line(s) in the dataset consist of the values, 10 per line, separated by a single space. The last line in the dataset may contain less than 10 values.

    输出

    Description

    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:

    2 5 1 3 3 7

    may be grouped as:

    (2 5) (1 3 3) (7)

    to yield an equal sum of 7.

    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.

    Input

    The first line of input contains a single integer P, (1 ≤ P ≤ 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 M, (1 ≤ M ≤ 10000), giving the total number of integers in the sequence. The remaining line(s) in the dataset consist of the values, 10 per line, separated by a single space. The last line in the dataset may contain less than 10 values.

    Output

    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.

    Sample Input

    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

    Sample Output

    1 7
    2 21
    3 2

    Source

    样例输入

    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 7
    2 21
    3 2

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部