PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000327. Giỏ kẹo có độ ngon lớn nhất (Maximum Tastiness of Candy Basket)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Giỏ kẹo có độ ngon lớn nhất (Maximum Tastiness of Candy Basket)

Maximum Tastiness of Candy Basket

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

A shop has nn candies, with candy ii priced at aia_i. A basket contains exactly kk distinct candies; different candies may have equal prices.

The tastiness of a basket is the smallest absolute price difference among all pairs in that basket. For instance, prices 2, 5 and 9 give tastiness min⁡(3,7,4)=3\min(3,7,4)=3.

Choose exactly kk candies to maximize the tastiness.

Input

The first line contains two integers n,kn,k, the number of available candies and the required basket size.

The second line contains nn integers a1,…,ana_1,\ldots,a_n, the candy prices.

Output

Print one integer: the maximum tastiness.

Subtasks

  • Subtask 1 (20 points): 2≤k≤n≤122\le k\le n\le12; 1≤ai≤1091\le a_i\le10^9.
  • Subtask 2 (30 points): 2≤k≤n≤1052\le k\le n\le10^5; 1≤ai≤1091\le a_i\le10^9; k=2k=2.
  • Subtask 3 (50 points): 2≤k≤n≤1052\le k\le n\le10^5; 1≤ai≤1091\le a_i\le10^9.

Examples

Input 1

6 3
13 5 1 8 21 2

Output 1

8

Explanation

Choose prices 5, 13 and 21, giving differences 8, 8 and 16. With minimum difference 9, the middle price would need to lie in [10,12] because the extremes are 1 and 21. No available candy has such a price.

Input 2

3 2
1 3 1

Output 2

2

Explanation

Select a candy priced 1 and the candy priced 3. The tastiness is 2, which is the maximum possible price difference.

Input 3

4 2
7 7 7 7

Output 3

0

Explanation

All four distinct candies cost 7, so every pair has price difference zero.