#K46592. Minimize Maximum Difference in Teams
Minimize Maximum Difference in Teams
Minimize Maximum Difference in Teams
You are given N employees with individual skill levels. Your task is to form a team of exactly K employees such that the difference between the strongest and the weakest member is minimized. Formally, if you have a sorted list of skill levels (a_1 \le a_2 \le \cdots \le a_N), you need to compute the value (\min_{1 \le i \le N-K+1} (a_{i+K-1} - a_i)). You should read the input from standard input and write the answer to standard output.
inputFormat
The first line contains two space-separated integers N and K. The second line contains N space-separated integers representing the skill levels of the employees.
outputFormat
Output a single integer representing the minimum possible difference between the highest and lowest skills in any team of K employees.## sample
6 3
10 20 13 40 45 50
10