HALLOWEEN EVE SOLUTION
In some other world, today is Halloween Eve.There are N trees planted in Mr. Smith’s garden. The height of the i-th tree (1≤i≤N) is h i meters. He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.
More specifically, let the height of the tallest decorated tree be hmax meters, and the height of the shortest decorated tree be hmin meters. The smaller the value hmax−hmin is, the better. What is the minimum possible value of hmax−hmin?
2≤K< N ≤105
hi is an integer
Input is given from Standard Input in the following format:
Print the minimum possible value of hmax−hmin.
Example Text Case
If we decorate the first, third and fifth trees, hmax=12,hmin=10 so hmax−hmin=2. This is
SOLUTION AFTER CONTEST(POLICY ISSUE)