#C11959. Minimum Subset Difference
Minimum Subset Difference
Minimum Subset Difference
You are given an array of n integers and an integer k. Your task is to select a subset of k elements from the array such that the difference between the maximum and the minimum element in the subset is minimized.
Formally, if the chosen subset is \( S \) then you need to minimize:
\( \text{diff}(S)=\max(S)-\min(S) \)
If \( k > n \), it is impossible to choose such a subset, so you should output \(-1\).
Note: The order of the elements in the input array does not affect your selection.
inputFormat
The first line contains two integers \( n \) and \( k \), where \( n \) is the number of elements in the array and \( k \) is the size of the subset to select. The second line contains \( n \) space-separated integers representing the array.
outputFormat
Output a single integer representing the minimum possible difference between the maximum and minimum elements among any chosen subset of size \( k \). If \( k > n \), output \(-1\).
## sample5 3
1 5 8 10 15
5