#BS0000327. Giỏ kẹo có độ ngon lớn nhất (Maximum Tastiness of Candy Basket)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 candies, with candy priced at . A basket contains exactly 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 .
Choose exactly candies to maximize the tastiness.
Input
The first line contains two integers , the number of available candies and the required basket size.
The second line contains integers , the candy prices.
Output
Print one integer: the maximum tastiness.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; .
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.