Need ideas in this problem.

Revision en2, by scar_face, 2021-03-04 11:14:03

I was asked this problem in Bytedance OA.

N points are given on a line and K special points can be setup anywhere. You have to find the sum of shortest distances for each point to any special point. I know a solution like grouping points, and then for each group, sum of distances to their median, but it didn't work that time. I am thinking some DP but unable to figure out.

Constraints are N, K <= 100

Coordinates of points 1 <= C[i] <= 10^4.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English scar_face 2021-03-04 11:14:03 35
en1 English scar_face 2021-03-03 17:49:46 472 Initial revision (published)