Choosing Numbers
Time limit1sMemory limit256 MB
Given a sequence, delete exactly K elements so that the sum of the largest gap and the smallest adjacent gap among the remaining elements is minimized.
- Level
Medium7 of 10
- Topics
- Sorting, Sliding window, Greedy, Two pointers
- Solved
- No attempts yet
Problem
You are given a sequence of numbers. Consider the differences between every pair of its elements. Let be the largest such difference and be the smallest. (Equivalently, is the maximum value minus the minimum value, and is the smallest gap between two adjacent values once the elements are sorted.)
A sequence of size is given. Write a program that removes exactly of its numbers so that, for the remaining numbers, the value is as small as possible.
Input
The first line contains two integers () and ().
The second line contains the elements of , separated by spaces ().
Output
Print the smallest possible value of on the first line.