EISW1 - Minimum Difference Between Highest and Lowest of K
Xem dạng PDF
Gửi bài giải
Điểm:
1,00 (OI)
Giới hạn thời gian:
1.0s
Giới hạn bộ nhớ:
256M
Input:
stdin
Output:
stdout
Dạng bài
You are given a 0-indexed integer array nums, where nums[i] represents the score of the ith student. You are also given an integer k.
Pick the scores of any k students from the array so that the difference between the highest and the lowest of the k scores is minimized.
Return the minimum possible difference. Hint: You can sort the array before using the Sliding window algorithm.
Input
The first line contains 2 integers n and k, which are the length of array nums and the window size, relatively.
The second line contains n integers which are the elements of array nums.
Output
Minimum possible difference
Example 1
Input
1 1
90
Output
0
Example 2
Input
4 2
9 4 1 7
Output
2
Bình luận