欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1669F.Eating Candies
Eating Candies
There are candies put from left to right on a table. The candies are numbered from left to right. The -th candy has weight . Alice and Bob eat candies.
Alice can eat any number of candies from the left (she can't skip candies, she eats them in a row).
Bob can eat any number of candies from the right (he can't skip candies, he eats them in a row).
Of course, if Alice ate a candy, Bob can't eat it (and vice versa).
They want to be fair. Their goal is to eat the same total weight of candies. What is the most number of candies they can eat in total?
Input
The first line contains an integer () — the number of test cases.
The first line of each test case contains an integer () — the number of candies on the table.
The second line of each test case contains integers () — the weights of candies from left to right.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, print a single integer — the maximum number of candies Alice and Bob can eat in total while satisfying the condition.
Note
For the first test case, Alice will eat one candy from the left and Bob will eat one candy from the right. There is no better way for them to eat the same total amount of weight. The answer is because they eat two candies in total.
For the second test case, Alice will eat the first three candies from the left (with total weight ) and Bob will eat the first three candies from the right (with total weight ). They cannot eat more candies since all the candies have been eaten, so the answer is (because they eat six candies in total).
For the third test case, there is no way Alice and Bob will eat the same non-zero weight so the answer is .
For the fourth test case, Alice will eat candies with weights and Bob will eat candies with weights , they each eat weight. There is no better partition so the answer is .
Samples
4
3
10 20 10
6
2 1 4 2 4 1
5
1 2 4 8 16
9
7 3 20 5 15 1 11 8 10
2
6
0
7
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |