AmazonOA #4
Cart Prefix Zero
估计中等可在线判题
One operation chooses a non-empty prefix of the array and adds 1 to all of its elements or subtracts 1 from all of them at once. Find the minimum number of operations needed to turn the whole integer array into 0. The array may contain negative numbers.
输入格式
The first line contains n (1..100000), and the second line contains n integers (−10⁹..10⁹). The answer may exceed the range of a 32-bit signed integer.
输出格式
Output a single integer, the answer required by the problem.
样例 1
输入:
5
3 2 0 0 -1
输出:
5
样例 2
输入:
1
0
输出:
0
样例 3
输入:
2
-2 2
输出:
6
样例说明
The differences in example 1 are 1, 2, 0, 1, −1, and the sum of their absolute values is 5.