CF1669F.Eating Candies

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are nn candies put from left to right on a table. The candies are numbered from left to right. The ii -th candy has weight wiw_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?

输入格式

The first line contains an integer tt ( 1t1041 \leq t \leq 10^4 ) — the number of test cases.

The first line of each test case contains an integer nn ( 1n21051 \leq n \leq 2\cdot10^5 ) — the number of candies on the table.

The second line of each test case contains nn integers w1,w2,,wnw_1, w_2, \dots, w_n ( 1wi1041 \leq w_i \leq 10^4 ) — the weights of candies from left to right.

It is guaranteed that the sum of nn over all test cases does not exceed 21052\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 22 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 77 ) and Bob will eat the first three candies from the right (with total weight 77 ). They cannot eat more candies since all the candies have been eaten, so the answer is 66 (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 00 .

For the fourth test case, Alice will eat candies with weights [7,3,20][7, 3, 20] and Bob will eat candies with weights [10,8,11,1][10, 8, 11, 1] , they each eat 3030 weight. There is no better partition so the answer is 77 .

首页