No.3185 Three Abs
問題文最終更新日: 2025-06-15 12:36:05
English (AI translation)
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence.
Back to the original
yukicoder contest 471
(順位表)
の他の問題:
Problem Statement
You are given an integer sequence $A = (A_1, A_2, \cdots, A_N)$ of length $N$. Here, $N \geq 3$ holds.
You choose $2$ integers $i, j$ satisfying $1 \leq i < j < N$. Your score is then $|A_1 + A_2 + \cdots + A_i| + |A_{i + 1} + A_{i + 2} + \cdots + A_j| + |A_{j + 1} + A_{j + 2} + \cdots + A_N|$.
Find the maximum score you can obtain.
You are given $T$ test cases; find the answer for each of them.
Input
$T$Here, $\mathrm{case}_i$ denotes the $i$-th test case, and each test case is given in the following format.
$\mathrm{case}_1$
$\mathrm{case}_2$
$\vdots$
$\mathrm{case}_T$
$N$
$A_1\ \ A_2\ \ \cdots A_N$
- $1 \leq T \leq 10^5$
- $3 \leq N \leq 2 \times 10^5$
- $-10^9 \leq A_i \leq 10^9$
- All input values are integers.
- In $1$ input file, the sum of $N$ does not exceed $5 \times 10^5$.
Output
For each test case, output the answer on $1$ line, followed by a newline.
Sample
Sample 1
Input
3
6
6 5 -4 3 -2 1
3
0 0 0
5
1 1 1 1 1
Output
17
0
5
- For the $1$-st test case, choosing $i = 2, j = 3$ as $i, j$ gives a score of $|6 + 5| + |-4| + |3 + (-2) + 1| = 17$. It can be proved that a score of $18$ or more cannot be obtained, so the answer is $17$.
- For the $2$-nd test case, the only possible choice of $i, j$ is $i = 1, j = 2$. The score in this case is $|0| + |0| + |0| = 0$.
- For the $3$-rd test case, the score is $5$ regardless of $i, j$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
蜜蜂