#K4911. Minimize Difficulty Difference
Minimize Difficulty Difference
Minimize Difficulty Difference
You are given n problems, each with a difficulty level, and you need to choose exactly k problems such that the difference between the maximum and minimum difficulty among the chosen problems is minimized.
Formally, if you select problems with difficulties \(d_1, d_2, \dots, d_k\) (after sorting the difficulties in non-decreasing order), you want to minimize the value of \[ \Delta = d_{max} - d_{min} = d_{i+k-1} - d_i \] for some valid index \(i\). Your task is to find this minimized difference.
Note: The input is read from standard input and the output should be written to standard output.
inputFormat
The first line contains two space-separated integers \(n\) and \(k\), where \(n\) is the total number of problems and \(k\) is the number of problems to select.
The second line contains \(n\) space-separated integers representing the difficulty levels of the problems.
outputFormat
Output a single integer which is the minimum possible difference between the highest and lowest difficulty among the chosen \(k\) problems.
## sample5 3
10 12 15 20 25
5
</p>