前缀AI (CI翻译)
You are given an array $a_1, a_2, \ldots, a_n$.
给定一个数组 $a_1, a_2, \ldots, a_n$。AI (CI翻译)
For each index $i = 2, 3, \ldots, n$ in order, perform the following:
对于每个下标 $i = 2, 3, \ldots, n$,按顺序执行以下操作:AI (CI翻译)
- Define
$s = a_1 + a_2 + \ldots + a_{i-1}$. - Replace
$a_i$with one of the following three values:$a_i - s$,$a_i$, or$a_i + s$.
- 定义
$s = a_1 + a_2 + \ldots + a_{i-1}$。 - 将
$a_i$替换为以下三个值之一:$a_i - s$、$a_i$或$a_i + s$。
Over all possible choices, find the maximum value of $\max(a_1, a_2, \ldots, a_n)$ after the process described above.
在所有可能的选择中,求执行上述过程后 $\max(a_1, a_2, \ldots, a_n)$ 的最大值。AI (CI翻译)
Input
输入格式
AI (CI翻译)Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
每个测试包含多个测试用例。第一行包含测试用例数量 $t$($1 \le t \le 10^4$)。接下来是各个测试用例的描述。AI (CI翻译)
The first line of each test case contains a single integer $n$ ($2 \le n \le 50$).
每个测试用例的第一行包含一个整数 $n$($2 \le n \le 50$)。AI (CI翻译)
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-50 \le a_i \le 50$).
每个测试用例的第二行包含 $n$ 个整数 $a_1, a_2, \ldots, a_n$($-50 \le a_i \le 50$)。AI (CI翻译)
Output
输出格式
AI (CI翻译)For each test case, output a single integer — the maximum achievable value of $\max(a_1, a_2, \ldots, a_n)$.
对于每个测试用例,输出一个整数,即 $\max(a_1, a_2, \ldots, a_n)$ 能够取得的最大值。AI (CI翻译)
Please note that the answer for some test cases won't fit into a 32-bit integer type, so you should use at least a 64-bit integer type in your programming language (like long long in C++).
请注意,某些测试用例的答案无法用 32 位整数类型表示,因此应在编程语言中使用至少 64 位的整数类型(例如 C++ 中的 long long)。AI (CI翻译)
Note
说明
AI (CI翻译)In the first test case, the final array can be made $[3, -8, -4, -13, 24]$, so the answer is $24$.
在第一个测试用例中,可以将最终数组变为 $[3, -8, -4, -13, 24]$,因此答案为 $24$。AI (CI翻译)
In the second test case, for $i = 2$, $s = a_1 = -1$. Replacing $a_2$ with $a_2 - s = 2 - (-1) = 3$ gives the answer $3$.
在第二个测试用例中,当 $i = 2$ 时,$s = a_1 = -1$。将 $a_2$ 替换为 $a_2 - s = 2 - (-1) = 3$ 后即可得到答案 $3$。AI (CI翻译)
In the third test case, the final array can be made $[1, 3, 7]$, so the answer is $7$.
在第三个测试用例中,可以将最终数组变为 $[1, 3, 7]$,因此答案为 $7$。AI (CI翻译)
In the fourth test case, replacing $a_2$ with $a_2 + s = -4$ makes $s = -6$ for $i = 3$. Replacing $a_3$ with $a_3 - s = -2 - (-6) = 4$ gives the final array $[-2, -4, 4]$, so the answer is $4$.
在第四个测试用例中,将 $a_2$ 替换为 $a_2 + s = -4$ 后,$i = 3$ 时的 $s = -6$。再将 $a_3$ 替换为 $a_3 - s = -2 - (-6) = 4$,得到最终数组 $[-2, -4, 4]$,因此答案为 $4$。AI (CI翻译)
样例
4
5
3 -5 1 -4 2
2
-1 2
3
1 2 3
3
-2 -2 -2
24
3
7
4
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。