K representatives on a line
Time limit2sMemory limit512 MB
For each K from 1 to N, place K real points on a line to minimize the total distance to all given points.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Divide and conquer, Greedy, Sorting
- Solved
- No attempts yet
Problem
You are given a sequence of integers . For a positive integer , choose real numbers , which do not have to be integers, so that the value of is as small as possible.
For every from to , find the smallest possible value of .
Input
The first line contains a positive integer ().
The second line contains the integers of the sequence , separated by spaces. Each value is between and . The sequence is not guaranteed to be sorted.
Output
Print numbers on one line, separated by spaces. The -th number is the smallest possible value of when the sequence has length . Every answer is an integer.
Hint
In the example you can take for , and for .