#K77712. Minimum Difficulty Range
Minimum Difficulty Range
Minimum Difficulty Range
You are given a list of problem difficulties. Your task is to select exactly k problems from the list such that when these difficulties are sorted in non-decreasing order, the difference between the maximum and minimum values is minimized.
Formally, given an array of integers \(A\) (of length \(n\)) and an integer \(k\) (with \(1 \leq k \leq n\)), find: \[ \min_{0 \leq i \leq n-k} \left( A_{(i+k-1)} - A_{(i)} \right) \]where \(A_{(i)}\) denotes the \(i\)-th smallest difficulty after sorting the array.
The input is read from standard input (stdin) and the output should be written to standard output (stdout).
inputFormat
The first line contains two space-separated integers \(n\) and \(k\), where \(n\) is the number of problems and \(k\) is the number of problems to choose.
The second line contains \(n\) space-separated integers representing the difficulty of each problem.
outputFormat
Output a single integer which is the minimum difference between the hardest and easiest problem in the chosen set of \(k\) problems.
## sample6 3
3 1 9 7 5 11
4