CF1741C.Minimize the Thickness

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a sequence a=[a1,a2,,an]a=[a_1,a_2,\dots,a_n] consisting of nn positive integers.

Let's call a group of consecutive elements a segment. Each segment is characterized by two indices: the index of its left end and the index of its right end. Denote by a[l,r]a[l,r] a segment of the sequence aa with the left end in ll and the right end in rr , i.e. a[l,r]=[al,al+1,,ar]a[l,r]=[a_l, a_{l+1}, \dots, a_r] .

For example, if a=[31,4,15,92,6,5]a=[31,4,15,92,6,5] , then a[2,5]=[4,15,92,6]a[2,5]=[4,15,92,6] , a[5,5]=[6]a[5,5]=[6] , a[1,6]=[31,4,15,92,6,5]a[1,6]=[31,4,15,92,6,5] are segments.

We split the given sequence aa into segments so that:

  • each element is in exactly one segment;
  • the sums of elements for all segments are equal.

For example, if aa = [ 55,45,30,30,40,10055,45,30,30,40,100 ], then such a sequence can be split into three segments: a[1,2]=[55,45]a[1,2]=[55,45] , a[3,5]=[30,30,40]a[3,5]=[30, 30, 40] , a[6,6]=[100]a[6,6]=[100] . Each element belongs to exactly segment, the sum of the elements of each segment is 100100 .

Let's define thickness of split as the length of the longest segment. For example, the thickness of the split from the example above is 33 .

Find the minimum thickness among all possible splits of the given sequence of aa into segments in the required way.

输入格式

The first line contains a single integer tt ( 1t1001 \le t \le 100 ) — the number of test cases.

Each test case is described by two lines.

The first line of each test case contains a single integer nn ( 1n20001 \le n \le 2000 ) — the length of the sequence aa .

The second line of each test case contains exactly nn integers: a1,a2,,ana_1, a_2, \dots, a_n ( 1ai1061 \le a_i \le 10^6 ) — elements of the sequence aa .

It is guaranteed that the sum of nn for all test cases does not exceed 20002000 .

输出格式

For each test case, output one integer — the minimum possible thickness of a split of the sequence aa into segments.

Note that there always exist a split, you can always consider whole sequence as one segment.

输入输出样例

  • 输入#1

    4
    6
    55 45 30 30 40 100
    4
    10 23 7 13
    5
    10 55 35 30 65
    6
    4 1 1 1 1 4

    输出#1

    3
    4
    2
    3

说明/提示

The split in the first test case is explained in the statement, it can be shown that it is optimal.

In the second test case, it is possible to split into segments only by leaving a single segment. Then the thickness of this split is equal to the length of the entire sequence, that is, 44 .

In the third test case, the optimal split will be [10,55],[35,30],[65][10, 55], [35, 30], [65] . The thickness of the split equals to 22 .

In the fourth test case possible splits are:

  • [4]+[1,1,1,1]+[4][4] + [1, 1, 1, 1] + [4] ;
  • [4,1,1]+[1,1,4][4, 1, 1] + [1, 1, 4] .
首页