Max Min

2.9

7 votes
Problem

you are given an array of size N. You need to select K elements from the array such that the difference between the max number among selected and the min number among selected array elements should be minimum. Print the minimum difference.

INPUT: First line N number i.e., length of array Second line K number Next N lines contains a number for each line

OUTPUT: Print the minimum possible difference

0<N<10^5 0<K<N 0<number<10^9

Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?