265. Fairest Selection
From n packets with given sizes, choose exactly m of them so that the
difference between the largest and smallest chosen is as small as possible.
Print that smallest possible difference.
Trying every group of m is hopeless. Sort first, and the answer becomes
obvious: the m packets closest in size must be next to each other in sorted
order, so only the n - m + 1 consecutive windows need checking.
That is a sliding window over sorted data, and the difference for each window is just its last element minus its first.
Constraints - `1 ≤ m ≤ n ≤ 200000` - `0 ≤ size ≤ 1000000000`
Input
The first line contains two integers n and m.
The second line contains n packet sizes.
Output
Print one integer, the smallest possible difference between the largest and smallest chosen packet.
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.