题目描述
Problem Description
You are given an integer sequence of length $ N $, $A_1, A_2, \cdots, A_N$. Consider an operation where you select $ K $ elements from this sequence and arrange them into a new sequence while preserving their relative order. However, you can only select both $ A_i $ and $ A_j $ $(i \neq j)$ if $|i - j| \geq D$.
Determine the smallest lexicographical sequence that can be formed under these constraints. If such an operation is impossible, output $ -1 $.
A sequence $x_1, x_2, \cdots, x_K$ is lexicographically smaller than $y_1, y_2, \cdots, y_K$ if the two sequences differ and $ x_i < y_i $ for the smallest integer $ i $ such that $x_i \neq y_i$.
Input Format
The input is given from the standard input in the following format:
$ N $ $ K $ $ D $ $ A_1 $ $ A_2 $ $\cdots$ $ A_N $
Output Format
Output the smallest lexicographical sequence that can be obtained if the operation is possible; otherwise, output $ -1 $.
Sample Input and Output
Sample Input #1
3 2 2
3 1 4
Sample Output #1
3 4
Sample Input #2
3 3 2
3 1 4
Sample Output #2
-1
Sample Input #3
3 2 1
3 1 4
Sample Output #3
1 4
Sample Input #4
4 2 2
3 6 5 5
Sample Output #4
3 5
Notes/Hints
Constraints
- $2 \leq N \leq 2 \times 10^5$
- $1 \leq D \leq N$
- $1 \leq K \leq N$
- $0 \leq A_i \leq 10^9$
- All inputs are integers
Sample Explanation 1
The sequence $ A $ is $\{3, 1, 4\}$. Under $ D = 2 $, the only way to select $ K = 2 $ elements is to choose the 1st and 3rd elements of $ A $, resulting in $\{3, 4\}$. Therefore, output $\{3, 4\}$.
Sample Explanation 2
The sequence $ A $ is $\{3, 1, 4\}$. Under $ D = 2 $, it is impossible to select $ K = 3 $ elements. Therefore, output $ -1 $.
Sample Explanation 3
The sequence $ A $ is $\{3, 1, 4\}$. Under $ D = 1 $, there are three ways to select $ K = 2 $ elements:
- Choose the 1st and 2nd elements of $ A $, resulting in $\{3, 1\}$.
- Choose the 1st and 3rd elements of $ A $, resulting in $\{3, 4\}$.
- Choose the 2nd and 3rd elements of $ A $, resulting in $\{1, 4\}$.
Therefore, output $\{1, 4\}$.
Sample Explanation 4
The sequence $ A $ is $\{3, 6, 5, 5\}$. Under $ D = 2 $, there are three ways to select $ K = 2 $ elements:
- Choose the 1st and 3rd elements of $ A $, resulting in $\{3, 5\}$.
- Choose the 1st and 4th elements of $ A $, resulting in $\{3, 5\}$.
- Choose the 2nd and 4th elements of $ A $, resulting in $\{6, 5\}$.
Therefore, output $\{3, 5\}$.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分