Username:   
Password:      

Pokemon Creed Forums < Sunkern's Studying Session < Solve the problem using C
Solve the problem using C
Favorite Thread Post Reply
Solve the problem using C
December 06, 2013 4:03:24am
    Post: #1 
[-]
Solve the problem using C
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.

CONSTTRAINTS
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 4


SAMPLE OUTPUT
0
1
3

EXPLANATION
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

Solve the problem and explain it please.

[you must login to view images]

Hello, i am Dialga2012. I like to make siggies. If you think you need a good(not excellent :O) sig visit my shop:
[you must login to view links]
Thank this message
Quote this message in a reply
December 24, 2013 11:11:15pm
    Post: #2 
[-]
wow this is realy detailed and it looks very difficult to know lol

[you must login to view images]
Thank this message
Quote this message in a reply
December 28, 2013 5:48:31pm
    Post: #3 
[-]
This message is hidden because this person has been banned.

This person's signature has been hidden because this person has been banned.
Thank this message
Quote this message in a reply
Post Reply


[-]
Board Statistics
Board Statistics
Our members have made a total of 526,171 posts in 39,218 threads (excluding the 'Miscellaneous' forum catergory, deleted posts and hidden forum sections).
We currently have 342,270 members registered on this Online Pokemon RPG.



© 2010 - 2019 Pokemon Creed Forums - Online Pokemon RPG / MMORPG - Server side coded by Alan and theme designed by Azagthoth. [Back To Top]