AtCoder Regular Contest 123
D
Inc, Dec - Decomposition
AtCoder
⌀ 2143
原题
← CE →
翻译中…

Problem Statement

翻译中…

Given is a sequence of integers $A = (A_1, \ldots, A_N)$.

翻译中…

Consider a pair of sequences of integers $B = (B_1, \ldots, B_N)$ and $C = (C_1, \ldots, C_N)$ that satisfies the following conditions:

翻译中…
  • $A_i = B_i + C_i$ holds for each $1\leq i\leq N$;
  • $B$ is non-decreasing, that is, $B_i\leq B_{i+1}$ holds for each $1\leq i\leq N-1$;
  • $C$ is non-increasing, that is, $C_i\geq C_{i+1}$ holds for each $1\leq i\leq N-1$.
翻译中…

Find the minimum possible value of $\sum_{i=1}^N \bigl(\lvert B_i\rvert + \lvert C_i\rvert\bigr)$.

翻译中…

Constraints

翻译中…
  • $1\leq N\leq 2\times 10^5$
  • $-10^8\leq A_i\leq 10^8$
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
A_1 A_2 \ldots A_N

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
3
1 -2 3
Output #1
10
One pair of sequences $B = (B_1, \ldots, B_N)$ and $C = (C_1, \ldots, C_N)$ that yields the minimum value is: - $B = (0, 0, 5)$, - $C = (1, -2, -2)$. Here we have $\sum_{i=1}^N \bigl(\lvert B_i\rvert + \lvert C_i\rvert\bigr) = (0+1) + (0+2) + (5+2) = 10$.
Input #2
4
5 4 3 5
Output #2
17
One pair of sequences $B$ and $C$ that yields the minimum value is: - $B = (0, 1, 2, 4)$, - $C = (5, 3, 1, 1)$.
Input #3
1
-10
Output #3
10
One pair of sequences $B$ and $C$ that yields the minimum value is: - $B = (-3)$, - $C = (-7)$.
题目信息
题号
arc123_d
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。