CF1844C.Particles

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You have discovered nn mysterious particles on a line with integer charges of c1,,cnc_1,\dots,c_n . You have a device that allows you to perform the following operation:

  • Choose a particle and remove it from the line. The remaining particles will shift to fill in the gap that is created. If there were particles with charges xx and yy directly to the left and right of the removed particle, they combine into a single particle of charge x+yx+y .

For example, if the line of particles had charges of [3,1,4,1,5,9][-3,1,4,-1,5,-9] , performing the operation on the 44 th particle will transform the line into [3,1,9,9][-3,1,9,-9] .

If we then use the device on the 11 st particle in this new line, the line will turn into [1,9,9][1,9,-9] .

You will perform operations until there is only one particle left. What is the maximum charge of this remaining particle that you can obtain?

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt ( 1t1041 \le t \le 10^4 ). The description of the test cases follows.

The first line of each test case contains a single integer nn ( 1n21051 \le n \le 2 \cdot 10^5 ).

The second line of each test case contains nn integers c1,,cnc_1,\dots,c_n ( 109ci109-10^9 \le c_i \le 10^9 ).

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5 .

输出格式

For each test case, output one integer, the maximum charge of the remaining particle.

输入输出样例

  • 输入#1

    3
    6
    -3 1 4 -1 5 -9
    5
    998244353 998244353 998244353 998244353 998244353
    1
    -2718

    输出#1

    9
    2994733059
    -2718

说明/提示

In the first test case, the best strategy is to use the device on the 44 th particle, then on the 11 st particle (as described in the statement), and finally use the device on the new 33 rd particle followed by the 11 st particle.

In the second test case, the best strategy is to use the device on the 44 th particle to transform the line into [998244353,998244353,1996488706][998244353,998244353,1996488706] , then on the 22 nd particle to transform the line into [2994733059][2994733059] . Be wary of integer overflow.

In the third test case, there is only one particle, so no operations can be performed.

首页