Computer Science
Time limit2sMemory limit512 MB
Find the smallest L such that for each a_i we can pick an interval [x_i, x_i+L] covering a_i and containing at least K of the given integers.
- Level
Hard8 of 10
- Topics
- Binary search, Sorting, Two pointers, Prefix sum
- Solved
- No attempts yet
Problem
Vera has integers .
A margin is a non-negative integer with the following property. You can choose integers so that for every with , the interval contains at least of Vera's integers and also contains . Equal values are counted separately, so a value that appears three times counts three times.
Compute the minimum possible margin.
Input
The first line contains integers and ().
The second line contains integers ().
Output
Print one line with one integer, the minimum possible margin.
Hint
For the first example, one valid choice is , , , , . The picture below shows that choice.
