cswork / OAOpen practice workspace

AmazonOA #249

Kth Smallest in Subarray

Estimated HardJudge-ready

Topics (AI-labelled)Stacks & HeapsTwo PointersBinary Search

For each contiguous window of length m in the array, from left to right, output its k-th smallest element; equal numbers at different positions each take their own rank. Output in increasing order of window start. The original statement was truncated; this rule is restored from what the original example states explicitly: windows of m=3, the 2nd smallest, and the output order.

Input

The first line contains n m k; the second line contains the array. The original text had no numeric bounds; this site uses 1≤k≤m≤n≤100000, −10^9≤element≤10^9.

Output

Output n−m+1 integers in order of window start, separated by spaces.

Example 1

Input:

4 3 2
3 1 4 2

Output:

3 2

Example 2

Input:

3 2 2
2 2 1

Output:

2 2

Example 3

Input:

1 1 1
-5

Output:

-5

Example notes

The answers are 3 2, 2 2 and −5. In the second example the two 2s are two separate elements.

Editorial

Loading solution…