CF596B.Wilbur and Array
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
小猪威尔伯又在摆弄数组了。他最初有一个由 n 个零组成的数组 a1,a2,…,an。在每一步操作中,他可以选择任意下标 i,然后对所有元素 ai,ai+1,…,an 同时加 1,或者同时减 1。他的目标是最终得到数组 b1,b2,…,bn。
显然,威尔伯希望以最少的操作步数达成这一目标,因此请你计算该最小步数。
输入格式
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — 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 ( - 109 ≤ b__i ≤ 109).
输入的第一行包含一个整数 n(1≤n≤200000)—— 表示数组 ai 的长度。初始时,每个位置 i 上的 ai=0,因此该数组并未在输入中给出。
输入的第二行包含 n 个整数 b1,b2,…,bn(−109≤bi≤109)。
输出格式
Print the minimum number of steps that Wilbur needs to make in order to achieve a__i = b__i for all i.
输出威尔伯为使所有 i 满足 ai=bi 所需的最少步数。
输入输出样例
输入#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.
在第一个样例中,威尔伯可以依次选择下标 1、2、3、4 和 5,并对相应的后缀加 1。
在第二个样例中,威尔伯首先选择下标 1 和 2 并对相应的后缀加 1,然后他选择下标 4 并减去 1。
输入解题思路,AI测评打分。不知道怎么写?