max-min

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

SAMPLE INPUT
5
3
1
2
3
4
5

SAMPLE OUTPUT
2

Source: hackerearth | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
N = int(input())
K = int(input())

arr = list(map(int, (input() for i in range(N))))
arr.sort()

print(min(arr[i+K-1] - arr[i] for i in range(N-K)))


a=[]
t,k=eval(input()),eval(input())
for _ in range(t):
	a.append(eval(input()))
a.sort()
t=[a[x+k-1]-a[x] for x in range(0,len(a)-k) ]
print(min(t))
	
	


N = eval(input())
K = eval(input())

assert 1 <= N <= 10**5
assert 1 <= K <= N

lis = []
for i in range(N):
	lis.append(eval(input()))

lis.sort()

for i in lis:
	assert 0 <= i <= 10**9

answer = 100000000000000000000

for index in range(N-K+1):
	diff = lis[index+K-1] - lis[index]

	if diff < answer:
		answer = diff

print(answer)