Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/qidiruv-eng-katta-mediana

Largest median

Hard 2000 ms 128 MB 95%
Share

An array $a$ of $n$ positive integers and a positive integer $k$ are given. The median of a segment of $L$ consecutive elements is the number in the $\lfloor (L + 1) / 2 \rfloor$-th place after sorting its elements in increasing order (for example, the median of 3 1 2 4 is $2$). Among the segments of length at least $k$, find the one with the largest median and print that median.

Array cells: a segment of length at least k is highlighted, the median is marked in its sorted form

Input

The first line contains two positive integers: $n$ and $k$.
The second line contains $n$ positive integers $a_{i}$.

Output

One positive integer — the largest median.

Note

$1 \le k \le n \le 2 \cdot 10^{4}$
$1 \le a_{i} \le 10^{9}$

Examples

Input #1
5 3
1 2 3 2 1
Output #1
2
Input #2
4 2
1 2 3 4
Output #2
3

Sign in to submit a solution

Signing up is free and takes a minute.