Minimize the sum of errors of representative integers

Given n integers between [0,10000] as D1,D2...,Dn, where there may be duplicates, and n can be huge:

I want to find k distinct representative integers (for example k=5) between [0,10000] as R1,R2,...,Rk, so the sum of errors of all the representative integers is minimized.

The error of a representative integer is defined below:

Assuming we have k representative integers in ascending order as {R1,R2...,Rk}, the error of Ri is : enter image description here

and i want to minimize the sum of errors of the k representative integers:

enter image description here

how can this be done efficiently?

EDIT1: The smallest of the k representative integers must be the smallest number in {D1,D2...,Dn}

EDIT2: The largest of the k representative integers must be the largest number in {D1,D2...,Dn} plus 1. For example when the largest number in {D1,D2...,Dn} is 9787 then Rk is 9788.

EDIT3: A concrete example is here:

D={1,3,3,7,8,14,14,14,30} and if k=5 and R is picked as {1,6,10,17,31} then the sum of errors is :

sum of errors=(1-1)+(3-1)*2+(7-6)+(8-6)+(14-10)*3+(30-17)=32

this is because 1<=1,3,3<6 , 6<=7,8<10, 10<=14,14,14<17, 17<=30<31

13
задан Mr.Wizard 12 May 2011 в 23:59
поделиться