84. Chocolate Distribution
EasySortingSliding Window
Each packet has some chocolates. Give one packet to each of m students so that the difference between the largest and smallest packet given is as small as possible. Print that minimum difference.
Input format
Line 1: n m Line 2: n packet sizes
Output format
The minimum difference.
Example 1
Input
7 3 7 3 2 4 9 12 56
Output
2
Example 2
Input
5 5 1 2 3 4 5
Output
4
Constraints
1 ≤ m ≤ n ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 6 test cases, most of them hidden.
Loading the MyLoginn IDE…