atcoder#ARC123D. [ARC123D] Inc, Dec - Decomposition
[ARC123D] Inc, Dec - Decomposition
Score : points
Problem Statement
Given is a sequence of integers .
Consider a pair of sequences of integers and that satisfies the following conditions:
- holds for each ;
- is non-decreasing, that is, holds for each ;
- is non-increasing, that is, holds for each .
Find the minimum possible value of $\sum_{i=1}^N \bigl(\lvert B_i\rvert + \lvert C_i\rvert\bigr)$.
Constraints
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
3
1 -2 3
10
One pair of sequences and that yields the minimum value is:
- ,
- .
Here we have $\sum_{i=1}^N \bigl(\lvert B_i\rvert + \lvert C_i\rvert\bigr) = (0+1) + (0+2) + (5+2) = 10$.
4
5 4 3 5
17
One pair of sequences and that yields the minimum value is:
- ,
- .
1
-10
10
One pair of sequences and that yields the minimum value is:
- ,
- .