Wilbur and Array
题意翻译
# 题目描述
小猪威尔伯又在试图修复数组了。他有一个数组 a[1],a[2],...,a[n] 最初由 n 个0组成。第一步,他可以选择任何一个下标 i 并让其下标之后的所有元素 a[i],a[i+1],...,a[n] 加1,或者减1。他的目标是得到数组 b[1],b[2],...,b[n]。
当然,威尔伯希望使用最少的步数挑战这个目标,并要求你计算这个值。
# 输入输出格式
## 输入格式
第一行是一个整数 n(1<=n<=200000) ,代表数组的长度。
因为整个数组初始元素全是0,所以数组的元素不会给出。
第二行包括 n 个整数 b[1],b[2],...,b[n] (-10^9<=b[i]<=10^9)
## 输出格式
输出最小的步数。
题目描述
Wilbur the pig is tinkering with arrays again. He has the array $ a_{1},a_{2},...,a_{n} $ initially consisting of $ n $ zeros. At one step, he can choose any index $ i $ and either add $ 1 $ to all elements $ a_{i},a_{i+1},...\ ,a_{n} $ or subtract $ 1 $ from all elements $ a_{i},a_{i+1},...,a_{n} $ . His goal is to end up with the array $ b_{1},b_{2},...,b_{n} $ .
Of course, Wilbur wants to achieve this goal in the minimum number of steps and asks you to compute this value.
输入输出格式
输入格式
The first line of the input contains a single integer $ n $ ( $ 1<=n<=200000 $ ) — the length of the array $ a_{i} $ . Initially $ a_{i}=0 $ for every position $ i $ , so this array is not given in the input.
The second line of the input contains $ n $ integers $ b_{1},b_{2},...,b_{n} $ ( $ -10^{9}<=b_{i}<=10^{9} $ ).
输出格式
Print the minimum number of steps that Wilbur needs to make in order to achieve $ a_{i}=b_{i} $ for all $ i $ .
输入输出样例
输入样例 #1
5
1 2 3 4 5
输出样例 #1
5
输入样例 #2
4
1 2 2 1
输出样例 #2
3
说明
In the first sample, Wilbur may successively choose indices $ 1 $ , $ 2 $ , $ 3 $ , $ 4 $ , and $ 5 $ , and add $ 1 $ to corresponding suffixes.
In the second sample, Wilbur first chooses indices $ 1 $ and $ 2 $ and adds $ 1 $ to corresponding suffixes, then he chooses index $ 4 $ and subtract $ 1 $ .