Minimize the sum of absolute difference of adjacent array elements

array

#1

Given an array A of N (N<=10^6) elements , you can choose any subarray and invert the sign of all elements lying in that subarray i.e positive elements are changed to negative and vice versa.

You have to apply this operation exactly once. Determine the minimum possible sum of absolute difference of adjacent array elements that can be obtained after applying the operation exactly once. -10^9<=A*<=10^9.

Link to problem: http://codeforces.com/gym/101522/problem/I

Please suggest how to approach this problem.


#2

Hi, I met you again, tips: when flipping symbols in the interval [L, R], the effect on the answer only exists at the endpoint, for example, when flipping the entire array, the answers was not changed. so the next steps are obvious。


#3

Thanks for the help mr. freeloop.


#4

exactly man… :slight_smile:
I just opened this tab for writing that answer…