cswork / OA打开练习工作台

AmazonOA #231

Get the Fewest Moves (~Operations~)~

估计中等可在线判题

考点(AI 标注)前缀和区间贪心调度

One operation chooses a non-empty prefix and applies +1 or −1 to all of its elements simultaneously. Find the minimum number of operations to make every element zero. These are not suffix operations.

输入格式

The first line contains n; the second line contains the integers. 1≤n≤100000, −10^9≤element≤10^9.

输出格式

Output a single integer, the answer.

样例 1

输入:

3
3 2 1

输出:

3

样例 2

输入:

5
3 2 0 0 -1

输出:

5

样例 3

输入:

2
-1 -1

输出:

1

样例说明

The answers are 3, 5 and 1. In the second example the absolute value of the first element cannot be used in place of the last.