Codeforces Round 703 (Div. 2)
D
Max Median
Codeforces
2100
原题
← C2E →
翻译中…

You are a given an array $a$ of length $n$. Find a subarray $a[l..r]$ with length at least $k$ with the largest median.

翻译中…

A median in an array of length $n$ is an element which occupies position number $\lfloor \frac{n + 1}{2} \rfloor$ after we sort the elements in non-decreasing order. For example: $median([1, 2, 3, 4]) = 2$, $median([3, 2, 1]) = 2$, $median([2, 1, 2, 1]) = 1$.

翻译中…

Subarray $a[l..r]$ is a contiguous part of the array $a$, i. e. the array $a_l,a_{l+1},\ldots,a_r$ for some $1 \leq l \leq r \leq n$, its length is $r - l + 1$.

翻译中…

Input

翻译中…

The first line contains two integers $n$ and $k$ ($1 \leq k \leq n \leq 2 \cdot 10^5$).

翻译中…

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq n$).

翻译中…

Output

翻译中…

Output one integer $m$ — the maximum median you can get.

翻译中…

Note

翻译中…

In the first example all the possible subarrays are $[1..3]$, $[1..4]$, $[1..5]$, $[2..4]$, $[2..5]$ and $[3..5]$ and the median for all of them is $2$, so the maximum possible median is $2$ too.

翻译中…

In the second example $median([3..4]) = 3$.

翻译中…

样例

Input #1
5 3
1 2 3 2 1
Output #1
2
InputCopy OutputCopy
Input #2
4 2
1 2 3 4
Output #2
3
InputCopy OutputCopy
题目信息
题号
1486D
时间限制
2 s
内存限制
256 MB
标签
二分
数据结构
动态规划

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。