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

#BS0000319. Cân bằng công suất (Low Power)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Cân bằng công suất (Low Power)

Low Power

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

There are n machines, each with two chips, and each chip requires exactly k batteries. Assign all 2nk batteries exactly once. A chip’s output is the minimum of its k battery outputs. Minimize the maximum absolute difference between the two chip outputs of any machine.

Input

  • The first line contains integers n,kn,k, the number of machines and the number of batteries per chip.
  • The second line contains exactly 2nk2nk integers p1,…,p2nkp_1,\ldots,p_{2nk}, the battery outputs.

Output

Print one integer: the minimum possible maximum difference between the two chip outputs of a machine.

Subtasks

  • Subtask 1 (20 points): 1≤n,k1\le n,k; 2nk≤122nk\le12; 1≤pi≤201\le p_i\le20.
  • Subtask 2 (30 points): 1≤n,k1\le n,k; 2nk≤1062nk\le10^6; 1≤pi≤1091\le p_i\le10^9; k=1k=1.
  • Subtask 3 (50 points): 1≤n,k1\le n,k; 2nk≤1062nk\le10^6; 1≤pi≤1091\le p_i\le10^9.

Examples

Input 1

2 3
1 2 3 4 5 6 7 8 9 10 11 12

Output 1

1

Explanation

Chip groups (1,3,5), (2,4,12), (6,8,9), (7,10,11) attain difference 1. Zero is impossible because outputs are distinct.

Input 2

2 2
3 1 3 3 3 3 3 3

Output 2

2

Explanation

One chip receives batteries of outputs 1 and 3, so its output is 1. Each of the other three chips receives two batteries of output 3. The machines have differences 2 and 0. A maximum below 2 is impossible because there is only one battery of output 1.