A15017 | Eating Candies
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There are $n$ candies put from left to right on a table. The candies are numbered from left to right. The $i$ -th candy has weight $w_i$ . 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?
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?
输入格式
The first line contains an integer $t$ ( $1 \leq t \leq 10^4$ ) — the number of test cases.
The first line of each test case contains an integer $n$ ( $1 \leq n \leq 2\cdot10^5$ ) — the number of candies on the table.
The second line of each test case contains $n$ integers $w_1, w_2, \dots, w_n$ ( $1 \leq w_i \leq 10^4$ ) — the weights of candies from left to right.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot10^5$ .
The first line of each test case contains an integer $n$ ( $1 \leq n \leq 2\cdot10^5$ ) — the number of candies on the table.
The second line of each test case contains $n$ integers $w_1, w_2, \dots, w_n$ ( $1 \leq w_i \leq 10^4$ ) — the weights of candies from left to right.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot10^5$ .
输出格式
For each test case, print a single integer — the maximum number of candies Alice and Bob can eat in total while satisfying the condition.
输入输出样例
输入 #1
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
输出 #1
2 6 0 7
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 $2$ 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 $7$ ) and Bob will eat the first three candies from the right (with total weight $7$ ). They cannot eat more candies since all the candies have been eaten, so the answer is $6$ (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 $0$ .
For the fourth test case, Alice will eat candies with weights $[7, 3, 20]$ and Bob will eat candies with weights $[10, 8, 11, 1]$ , they each eat $30$ weight. There is no better partition so the answer is $7$ .
For the second test case, Alice will eat the first three candies from the left (with total weight $7$ ) and Bob will eat the first three candies from the right (with total weight $7$ ). They cannot eat more candies since all the candies have been eaten, so the answer is $6$ (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 $0$ .
For the fourth test case, Alice will eat candies with weights $[7, 3, 20]$ and Bob will eat candies with weights $[10, 8, 11, 1]$ , they each eat $30$ weight. There is no better partition so the answer is $7$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted