~/algor $ cat problems/qidiruv-eng-katta-mediana
Largest median
Hard
2000 ms
128 MB
95%
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.
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