欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1741C.Minimize the Thickness
Minimize the Thickness
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.
Input
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 .
Output
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.
Note
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, .
In the third test case, the optimal split will be . The thickness of the split equals to .
In the fourth test case possible splits are:
- ;
- .
Samples
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
3
4
2
3
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |