You are not logged in. Please login at www.codechef.com to post your questions!

×

Minimize the sum of absolute difference of adjacent array elements

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[i]<=10^9.

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

Please suggest how to approach this problem.

asked 23 May, 22:18

lakh's gravatar image

4★lakh
1395
accept rate: 23%

edited 23 May, 22:54


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。

link

answered 23 May, 22:54

freeloop's gravatar image

6★freeloop
3343
accept rate: 47%

Thanks for the help mr. freeloop.

(23 May, 22:58) lakh4★
1

exactly man... :)
I just opened this tab for writing that answer..

(23 May, 23:06) l_returns5★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×824

question asked: 23 May, 22:18

question was seen: 126 times

last updated: 26 May, 15:47