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
|
||||||||||||
2014-03-15 20:28:46 RAJAT SINGH
Very easy problem got AC in second time...... |
||||||||||||
2014-01-17 09:16:53 Amit garg
running program correctly on ideone but showing comile error here Last edit: 2014-01-17 09:17:30 |
||||||||||||
2013-07-12 06:14:16 Rudradeep Mukherjee
Don't know what happened. Submitted the same code again and it got AC. :) Last edit: 2013-07-12 06:18:52 |
||||||||||||
2013-07-07 19:53:08 Hasil Sharma
O(nlogn+n) !! indeed |
||||||||||||
2013-07-04 21:45:01 Rana Saha
cakewalk! |
||||||||||||
2013-06-11 11:31:04 Centurion
can anyone explain this test case and what will be the answer for it? 5 3 1 9 16 21 22 |
||||||||||||
2013-05-21 15:24:36 Aswin Murugesh
I am getting WA but the given test cases are giving correct answers. Any tricky test cases? |
||||||||||||
2013-03-14 20:59:14 Shubham Sharma
very easy |
||||||||||||
2013-03-07 17:02:36 ***
plzz give some more test cases |
||||||||||||
2012-08-21 11:59:33 Secret
my code is accepted in O(nlogn+n).no need to I/O optimization ... |