Scenic Walkway

Time limit: 0.3s Memory limit: 16MB Input: Output:

Task

The managers of Gardaland Theme Park are building a new attraction, consisting of a sequence of NN chambers of horrors, each located at a different height of HiH_i meters. Together with the attraction, they also plan to build a scenic walkway following most of the chambers from the outside.

In order to maximise the visibility of the new attraction, they need to carefully plan the altitude at which to build the walkway. For this reason they hired Giorgio and William, who calculated that it would be best if at least KK chambers were clearly visible from the walkway. Given a set of chambers, define its spread as the difference between the highest and the lowest chamber in the set. Find the smallest possible spread for a set of KK chambers!

Input data

The first line contains the two integers NN and KK. The second line contains NN integers HiH_i.

Output data

You need to write a single line with an integer: the smallest possible spread for a set of KK chambers.

Constraints and clarifications

  • 2KN10000002 \le K \le N \le 1\,000\,000.
  • 0Hi10000000 \le H_i \le 1\,000\,000 for each i=0N1i=0\ldots N-1.
# Points Constraints
1 5 Examples.
2 30 N10N \le 10.
3 25 N1000N \le 1000, K=2K = 2.
4 20 N1000N \le 1000.
5 20 No additional limitations.

Example 1

stdin

6 2
50 60 80 40 10 80

stdout

0

Explanation

In the first sample case the set of chambers with lowest spread is {80,80}\{80,80\}.

Example 2

stdin

10 3
67 90 22 79 95 89 76 21 65 99

stdout

6

Explanation

In the second sample case the set of chambers with lowest spread is {90,95,89}\{90,95,89\}.

Log in or sign up to be able to send submissions!