#P8978. 「DTOI-4」中位数

    ID: 9904 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>动态规划 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 1lrn1 \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 1n101 \leq n \leq 10 10pts10 \operatorname{pts}
22 1n1001 \leq n \leq 100
33 1n1031 \leq n \leq 10^3
44 1n1041 \leq n \leq 10^4 20pts20 \operatorname{pts}
55 1n1051 \leq n \leq 10^5
66 No special constraints. 30pts30 \operatorname{pts}

For 100%100\% of the testdata, 1n4×1051 \leq n \leq 4 \times 10^5, 0kn0 \leq k \leq n, and 0ai1090 \leq a_i \leq 10^9.

Translated by ChatGPT 5