Sitting Side by Side

Правка en1, от sid9406, 2020-11-22 10:19:35

I was solving problem C from the Google kickstart Round H and this problem requires me to solve the below task :-

There are n points on the x-axis and two or more points can coincide . We want to arrange these n points on x axis such that they become adjacent. Each movement of 1 unit has cost of 1 unit . What is the minimum cost of doing this activity ?

My approach :- Sort the points and fix the position of the median point(if n is even you can fix any median) , then centre all other points around this median .

can somebody explain why this approach is incorrect and if you know the correct approach pls share.

Thanks

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский sid9406 2020-11-22 10:19:35 659 Initial revision (published)