AMR10G  Christmas Play
My kid's kindergarten class is putting up a Christmas play. (I hope he gets the lead role.) The kids are all excited, but the teacher has a lot of work. She has to produce costumes for a scene with K soldiers. She wants to buy all the costumes in the same size, allowing for some small amount of length alteration to be done by the kids' parents later. So she has taken all the kids' height measurements. Can you help her select K kids from her class of N to play the soldier role, such that the height difference between the tallest and shortest in the group is minimized, and alternations will be easiest? Tell her what this minimum difference is.
INPUT
The first line contains the number of test cases T. T test cases follow each containing 2 lines.
The first line of each test case contains 2 integers N and K.
The second line contains N integers denoting the height of the N kids.
OUTPUT
Output T lines, each line containing the required answer for the corresponding test case.
CONSTRAINTS
T <= 30
1 <= K <= N <= 20000
1 <= height <= 1000000000
SAMPLE INPUT
3 3 1 2 5 4 3 2 5 2 4 3 3 2 5 4SAMPLE OUTPUT
0 1 3EXPLANATION
In the first test case, the teacher needs to only select 1 kid and hence she can choose any kid since the height difference is going to be 0.
In the second test case, the teacher can choose kids with height 4 and 5.
In the third test case, the teacher is forced to choose all 3 kids and hence the answer = 52 = 3
hide comments
rehanrahi:
20171004 15:17:33
guys if you are stuck then simply use window sliding technique .it might be useful 

touchstone:
20170701 16:30:55
AC in 1 go :D is this even a question ? :P (timepass) 

ramesh_961:
20170622 18:04:32
AC in one go!! Use Merge sort!! 

shauryauppal:
20170608 22:33:25
step1 >sort(arr)


piyushbharti:
20170522 17:33:17
try not to declare a global array!!my one was giving wa for same


aayushbhaskar:
20170521 09:26:51
getting TLE in C even after using qsort pls help :(


Rajat Gautam:
20170521 04:35:00
Decrease min value if getting CE . 

gurjits909:
20170515 22:46:12
i used quicksort that results in tle ,,,everyone suggesting about quicksort so why im getting tle 

rohit9934:
20170502 08:38:10
silliest problem, using 1e7 gives wrong ans even they say int will work, but INT_MAX gives AC. cost 4 WA. 

nilabja16180:
20170219 18:52:56
AC in one GO!

Added by:  Varun Jalan 
Date:  20101213 
Time limit:  1s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ASM64 
Resource:  ICPC Asia regionals, Amritapuri 2010 