2

Min abs difference of K points in an array.

 2 years ago
source link: http://codeforces.com/blog/entry/96646
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Given an array A of size n i.e., A = {A_1, A_2, ... A_n}

you are given K. you can choose any K integers (not necessarily from the given array)
i.e, X_1, X_2, X_3 .... X_K
Now, we define a function F for each A_i, such that F_i = min(abs(A_i - X_j)) where 1<= j <=K.

find the minimum value of F_1 + F_2 + .... F_n.
constraints:

1 <= n <= 10^5
1<= K <= n

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK