#P8978. 「DTOI-4」中位数

    ID: 9904 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度NOI/NOI+/CTS 上传者: 标签>动态规划 DP二分单调队列2023洛谷原创O2优化

「DTOI-4」中位数

Problem Description

Given an integer sequence aa of length nn, you may perform the following operation at most kk times:

  • Choose an interval [l,r][l, r] such that 1≤l≤r≤n1 \leq l \leq r \leq n, and replace all numbers in [l,r][l, r] with the median of this interval.

You want to make the minimum value of aa as large as possible after the operations.

Definition of the median here: for a sequence of length lenlen, its median is defined as the ⌈len2⌉\left\lceil \frac{len}{2} \right\rceil-th smallest number in the sequence.

Input Format

The first line contains two integers n,kn, k.

The second line contains nn integers a1,a2,⋯ ,ana_1, a_2, \cdots, a_n.

Output Format

Output one line containing the maximum possible value of the minimum element of the sequence after at most kk operations.

10 2
2 8 3 2 5 7 10 4 9 7
7
30 3
1 0 1 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0
0
31 3
1 0 1 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1
1

Hint

Subtask\textbf{Subtask} nn Score
11 1≤n≤101 \leq n \leq 10 10pts⁡10 \operatorname{pts}
22 1≤n≤1001 \leq n \leq 100
33 1≤n≤1031 \leq n \leq 10^3
44 1≤n≤1041 \leq n \leq 10^4 20pts⁡20 \operatorname{pts}
55 1≤n≤1051 \leq n \leq 10^5
66 No special constraints. 30pts⁡30 \operatorname{pts}

For 100%100\% of the testdata, 1≤n≤4×1051 \leq n \leq 4 \times 10^5, 0≤k≤n0 \leq k \leq n, and 0≤ai≤1090 \leq a_i \leq 10^9.

Translated by ChatGPT 5