How to convert an array into a strictly increasing array?

Правка en2, от codemode, 2019-06-19 20:08:31

This is a problem from a past hiring contest of Hackerrank. We are given an array which contains at max 10^4 elements. Total cost is defined as the sum of absolute difference of the old value of the element and the new value of the element.

Ex: 10 6 3 2 2000

Minimum Cost: 11

1st element 10 can be changed to 6. Cost = abs(10 — 6) = 4.

3rd element 3 can be changed to 6. Cost = abs(3 — 6) = 3.

4th element 2 can be changed to 6. Cost = abs(2 — 6) = 4.

So total cost = 11

Range of elements: [1, 10^9]

How can I apply dynamic programming to solve it? Thanks :-)

Теги #dp

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский codemode 2019-06-19 20:08:31 16
en1 Английский codemode 2019-06-19 20:04:25 650 Initial revision (published)