Problem Summary
Given an array B of N positive integers, and the relationship between array A and B: 1 ≤ A[i] ≤ B[i] (1 ≤ i ≤ N), find the maximum of S = sum{|A[i] - A[i-1]|}, 2 ≤ i ≤ N.
Solution
To find max S, we need to determine the values of A[i].
First, we can prove that for any i, we only need to consider 1 and B[i], i.e. A[i] = 1 or A[i] = B[i].
The rest is trivial.
Code
|
|