CF1669F.Eating Candies
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 wi. 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?
桌面上从左到右摆放着 n 颗糖果。糖果从左到右编号。第 i 颗糖果的重量为 wi。Alice 和 Bob 轮流吃糖果。
Alice 可以从左侧吃任意数量的糖果(她不能跳过糖果,必须连续地从左端开始吃)。
Bob 可以从右侧吃任意数量的糖果(他不能跳过糖果,必须连续地从右端开始吃)。
当然,如果 Alice 吃了一颗糖果,Bob 就不能再吃它(反之亦然)。
他们希望做到公平:目标是两人所吃糖果的总重量相等。那么,他们最多一共能吃多少颗糖果?
输入格式
The first line contains an integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains an integer n (1≤n≤2⋅105) — the number of candies on the table.
The second line of each test case contains n integers w1,w2,…,wn (1≤wi≤104) — the weights of candies from left to right.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)—— 桌子上糖果的数量。
每个测试用例的第二行包含 n 个整数 w1,w2,…,wn(1≤wi≤104)—— 从左到右各糖果的重量。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, print a single integer — the maximum number of candies Alice and Bob can eat in total while satisfying the condition.
对于每个测试用例,输出一个整数——Alice 和 Bob 在满足条件的前提下总共能吃的糖果的最大数量。
输入输出样例
输入#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.
对于第一个测试用例,Alice 将从左侧吃掉一颗糖果,Bob 将从右侧吃掉一颗糖果。这是他们吃到相同总重量的最优方案。答案为 2,因为他们总共吃了两颗糖果。
对于第二个测试用例,Alice 将从左侧吃掉前三颗糖果(总重量为 7),Bob 将从右侧吃掉前三颗糖果(总重量也为 7)。由于所有糖果均已吃完,他们无法再吃更多糖果,因此答案为 6(因为他们总共吃了六颗糖果)。
对于第三个测试用例,不存在 Alice 和 Bob 能吃到相同非零重量的方案,因此答案为 0。
对于第四个测试用例,Alice 将吃重量为 [7,3,20] 的糖果,Bob 将吃重量为 [10,8,11,1] 的糖果,两人各自吃到的总重量均为 30。不存在更优的划分方式,因此答案为 7。
输入解题思路,AI测评打分。不知道怎么写?