欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1899B.250 Thousand Tons of TNT
250 Thousand Tons of TNT
Alex is participating in the filming of another video of BrMeast, and BrMeast asked Alex to prepare 250 thousand tons of TNT, but Alex didn't hear him well, so he prepared boxes and arranged them in a row waiting for trucks. The -th box from the left weighs tons.
All trucks that Alex is going to use hold the same number of boxes, denoted by . Loading happens the following way:
- The first boxes goes to the first truck,
- The second boxes goes to the second truck,
- The last boxes goes to the -th truck.
Upon loading is completed, each truck must have exactly boxes. In other words, if at some point it is not possible to load exactly boxes into the truck, then the loading option with that is not possible.
Alex hates justice, so he wants the maximum absolute difference between the total weights of two trucks to be as great as possible. If there is only one truck, this value is .
Alex has quite a lot of connections, so for every , he can find a company such that each of its trucks can hold exactly boxes. Print the maximum absolute difference between the total weights of any two trucks.
Input
The first line contains one integer () — the number of test cases.
The first line of each test case contains one integer () — the number of boxes.
The second line contains integers () — the weights of the boxes.
It is guaranteed that the sum of for all test cases does not exceed .
Output
For each test case, print a single integer — the answer to the problem.
Note
In the first case, we should pick two trucks, so the first one will have only the first box, and the second one will have only the second box.
In the second case, we should pick six trucks, so the maximum will be , the minimum will be , and the answer is .
In the third case, for any possible , the trucks will have the same total weight of boxes, so the answer is .
Samples
5
2
1 2
6
10 2 3 6 1 3
4
1000000000 1000000000 1000000000 1000000000
15
60978 82265 78961 56708 39846 31071 4913 4769 29092 91348 64119 72421 98405 222 14294
8
19957 69913 37531 96991 57838 21008 14207 19198
1
9
0
189114
112141
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |