#BS0000353. Giảm nhỏ nhất chênh lệch lớn nhất của các cặp (Minimize the Maximum Difference of Pairs)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Giảm nhỏ nhất chênh lệch lớn nhất của các cặp (Minimize the Maximum Difference of Pairs)
Minimize the Maximum Difference of Pairs
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
An array contains nonnegative integers indexed from to . Select exactly pairs of indices , where , using each index at most once.
A pair has difference . The cost of a selection is the largest difference among its pairs, or when . Determine the minimum achievable cost.
Input
The first line contains integers , the array length and required number of pairs.
The second line contains integers .
Output
Print the minimum cost as one integer.
Subtasks
- Subtask 1 (20 points): ; ; for every .
- Subtask 2 (30 points): ; ; for every .
- Subtask 3 (50 points): ; ; for every .
Examples
Input 1
6 2
10 1 2 7 1 3
Output 1
1
Explanation
Choose indices with values and with values . The differences are and . Only one equal-value pair exists, so two zero-difference pairs are impossible.
Input 2
4 1
4 2 1 2
Output 2
0
Explanation
Indices both hold . Their difference is , the lower bound for any difference.
Input 3
1 0
7
Output 3
0
Explanation
No pairs are required since ; the defined cost is .