1669F.md (2384B)
1 Source: https://codeforces.com/problemset/problem/1669/F 2 3 F. Eating Candies 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 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. 22 23 Alice can eat any number of candies from the left (she can't skip candies, she eats them in a row). 24 25 Bob can eat any number of candies from the right (he can't skip candies, he eats them in a row). 26 27 Of course, if Alice ate a candy, Bob can't eat it (and vice versa). 28 29 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? 30 31 Input 32 33 The first line contains an integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. 34 35 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. 36 37 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. 38 39 It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot10^5$. 40 41 Output 42 43 For each test case, print a single integer — the maximum number of candies Alice and Bob can eat in total while satisfying the condition. 44 45 Example 46 47 Input 48 49 ``` 50 4 51 52 3 53 54 10 20 10 55 56 6 57 58 2 1 4 2 4 1 59 60 5 61 62 1 2 4 8 16 63 64 9 65 66 7 3 20 5 15 1 11 8 10 67 ``` 68 69 Output 70 71 ``` 72 2 73 6 74 0 75 7 76 ``` 77 78 Note 79 80 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. 81 82 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). 83 84 For the third test case, there is no way Alice and Bob will eat the same non-zero weight so the answer is $0$. 85 86 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$.