#C4416. Minimum Skill Difference
Minimum Skill Difference
Minimum Skill Difference
Given (N) participants with different skill levels, your task is to form a team of exactly (K) members such that the difference between the highest and lowest skill levels in the team is minimized. You are required to compute and output this minimum difference.
The problem is solved by sorting the list of skill levels and then sliding a window of size (K) over the sorted list to find the smallest difference between the first and last elements in the window.
inputFormat
The input is given via standard input (stdin). The first line contains two integers (N) and (K) separated by a space, where (N) is the number of participants and (K) is the size of the team. The second line contains (N) integers representing the skill levels of the participants, separated by spaces.
outputFormat
Output a single integer representing the minimum possible difference between the highest and lowest skill levels in any team of size (K). The output should be written to standard output (stdout).## sample
6 3
10 20 30 40 50 60
20