Submit | All submissions | Best solutions | Back to list |
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
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 = 5-2 = 3
Added by: | Varun Jalan |
Date: | 2010-12-13 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | ICPC Asia regionals, Amritapuri 2010 |
hide comments
|
||||||||||||
2015-01-07 16:43:21 Anvesh Kumar Arrabochu
Submitted same code two times, got WA at first and AC, the second time and heights better be in nano metres or something :P |
||||||||||||
2014-11-18 09:25:54 Madhur Bhargava
* O(NlogN+ N) time AC!!! Last edit: 2014-11-18 09:26:09 |
||||||||||||
2014-09-04 16:02:02 Anubhav Mathur
Judge is drunked, with same code 5 compilation errors then ac o.O |
||||||||||||
2014-08-01 09:05:43 Diptesh Patel
"0.14"sec in C++4.3.2 :D Last edit: 2014-08-01 09:06:03 |
||||||||||||
2014-07-26 07:15:36 Baojun Wang
haskell O(nlogn+n) = TLE? please check 12022628 |
||||||||||||
2014-07-22 11:02:22 Arjun Verma
very easy with stl ! |
||||||||||||
2014-07-06 23:48:20 Rajat (1307086)
Despite being a served dish,not reading the ques properly caused me several wrong answer. Now A.C in .65s.But here thing is to beat .18s |
||||||||||||
2014-07-01 19:49:27 j1k7_7(JaskamalKainth)
0.18sec in C.:D |
||||||||||||
2014-06-27 23:19:18 Rachit
spoj is drunk compiation error first then AC with same code LOL :P |
||||||||||||
2014-06-12 15:41:31 pandu ranga rao
i got AC after 3 WA.comments helped me. |