#ARC098C. [ARC098E] Range Minimum Queries

[ARC098E] Range Minimum Queries

Score : 600600 points

Problem Statement

You are given an integer sequence AA of length NN and an integer KK. You will perform the following operation on this sequence QQ times:

  • Choose a contiguous subsequence of length KK, then remove the smallest element among the KK elements contained in the chosen subsequence (if there are multiple such elements, choose one of them as you like).

Let XX and YY be the values of the largest and smallest element removed in the QQ operations. You would like XYX-Y to be as small as possible. Find the smallest possible value of XYX-Y when the QQ operations are performed optimally.

Constraints

  • 1N20001 \leq N \leq 2000
  • 1KN1 \leq K \leq N
  • 1QNK+11 \leq Q \leq N-K+1
  • 1Ai1091 \leq A_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK QQ

A1A_1 A2A_2 ...... ANA_N

Output

Print the smallest possible value of XYX-Y.

5 3 2
4 3 1 5 2
1

In the first operation, whichever contiguous subsequence of length 33 we choose, the minimum element in it is 11. Thus, the first operation removes A3=1A_3=1 and now we have A=(4,3,5,2)A=(4,3,5,2). In the second operation, it is optimal to choose (A2,A3,A4)=(3,5,2)(A_2,A_3,A_4)=(3,5,2) as the contiguous subsequence of length 33 and remove A4=2A_4=2. In this case, the largest element removed is 22, and the smallest is 11, so their difference is 21=12-1=1.

10 1 6
1 1 2 3 5 8 13 21 34 55
7
11 7 5
24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784
451211184