[Solution] Minimize the Thickness Codeforces Solution
You are given a sequence consisting of 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 segment of the sequence with the left end in and the right end in , i.e. .
For example, if , then , , are segments.
We split the given sequence into segments so that:
- each element is in exactly one segment;
- the sums of elements for all segments are equal.
For example, if = [], then such a sequence can be split into three segments: , , . Each element belongs to exactly segment, the sum of the elements of each segment is .
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 .
Find the minimum thickness among all possible splits of the given sequence of into segments in the required way.
The first line contains a single integer () — the number of test cases.
Each test case is described by two lines.
The first line of each test case contains a single integer () — the length of the sequence .
The second line of each test case contains exactly integers: () — elements of the sequence .
It is guaranteed that the sum of for all test cases does not exceed .
For each test case, output one integer — the minimum possible thickness of a split of the sequence into segments.
Note that there always exist a split, you can always consider whole sequence as one segment.
No comments:
Post a Comment