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

#BS0000419. Xử lý ảnh (Photo Processing)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Xử lý ảnh (Photo Processing)

Photo Processing

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn photos with contrast values viv_i. Partition them into groups so that each photo belongs to exactly one group and each group contains at least kk photos. Photos in a group need not be consecutive in their original order.

The processing time of a group is its largest contrast minus its smallest contrast. Groups run in parallel, so the overall time is the largest of their processing times.

Find the minimum possible overall time.

Input

The first line contains integers n,kn,k.

The second line contains nn integers v1,v2,…,vnv_1,v_2,\ldots,v_n.

Output

Print the minimum overall time as an integer.

Subtasks

  • Subtask 1 (20 points): 1≤k≤n≤1001\le k\le n\le 100; 1≤i≤n1\le i\le n; 1≤vi≤1091\le v_i\le10^9.
  • Subtask 2 (30 points): 1≤k≤n≤50001\le k\le n\le 5000; 1≤i≤n1\le i\le n; 1≤vi≤1091\le v_i\le10^9.
  • Subtask 3 (50 points): 1≤k≤n≤3000001\le k\le n\le 300000; 1≤i≤n1\le i\le n; 1≤vi≤1091\le v_i\le10^9.

Examples

Input 1

5 2
50 110 130 40 120

Output 1

20

Explanation 1

The groups [40,50] and [110,120,130] have spreads 10 and 20. A smaller bound cannot accommodate the last three photos.

Input 2

4 1
2 3 4 1

Output 2

0

Explanation 2

Singleton groups have zero spread.