Suppose we have $n$ real numbers $a_1, a_2, \ldots, a_n$. We know that the solution which minimizes $$ \sum_{i=1}^n |x-a_i| $$ is $x^*=$ median of $a_1, a_2\ldots, a_n$.
Now suppose that we should choose $k<n$ numbers, namely $x^*_1, x^*_2, \ldots, x^*_k$ which corresponds to the $a_i$'s. For example $x^*_1$ corresponds to $a_1$ and $a_2$; $x^*_2$ corresponds to $a_3$, $a_4$ and $a_5$ etc. which minimizes $$ |x^*_1-a_1| + |x^*_1-a_2| + |x^*_2-a_3|+ x^*_2-a_4|+ |x^*_2-a_5|+ \ldots + |x^*_k-a_n| $$
Let me give a more concrete example:
Suppose we have 2,4,5,11,14 and $k=2$. Thus we need to choose $x_1$ and $x_2$. If we choose $x_1=5$ and associate it to 2,4 and 5; $x_2=11$ and associate it to 11 and 14 we get $$ |2-5|+|4-5|+|5-5|+|11-11|+|14-11|=3+1+3=7 $$
The question is how we can choose such $x_k$'s and how we should associate them to $a_i$'s. Is there any algorithm?