convert one array to another

Правка en2, от Sudhanshu_Kumar, 2019-10-28 09:34:44

Found this interesting problem:

Two integer arrays A and B are given. We need to convert array A to array B using some operation. Operation is defined as follows: Select any element from A decrease its value by 1 and add it to one of the two neighbours.

The array given is circular, meaning the last element can give its value to the first element.

Find the minimum cost to convert array A to array B, where cost id defined as the distance between them, distance between any consecutive element is 1.

Constraints: A,B<=100.

ex: A=[2,3,1,5] B=[2,2,1,6] We need to convert A to B, subtract 1 from index 1 of A i.e. element 3 and give it to 1 making it 2, now he array A is [2,2,2,5]. Now remove 1 from index 2(element 2) and give it to element 5 making it 6, now the array becomes [2,2,1,6], so total cost is 2.

Any suggestion to proceed to this problem.

Теги #help

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский Sudhanshu_Kumar 2019-10-28 09:34:44 297
en1 Английский Sudhanshu_Kumar 2019-10-28 08:04:48 614 Initial revision (published)