#P10878. [JRKSJ R9] 在相思树下 III

    ID: 12289 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>2024洛谷原创O2优化

[JRKSJ R9] 在相思树下 III

Background

I know.

No matter how much I am obsessed with him, he cannot be mine alone.

Just treat it as God loving the world, distant and gentle.

Holding hands is not necessary.

Across tens of millions of light-years, the universe offers a kiss.

It can still be felt clearly.

No need.

To force it.

To fit yourself into that made-up role.

Problem Description

You are given a sequence a1…na_{1\dots n} of length nn. You need to perform two types of operations on it for a total of n−1n-1 times.

For a sequence b1…lb_{1\dots l} of length ll, performing one operation will turn it into a sequence c1…l−1c_{1\dots l-1} of length l−1l-1:

  • In operation 1, ∀i∈[1,l),ci=max⁡(bi,bi+1)\forall i\in[1,l),c_i=\max(b_i,b_{i+1}).
  • In operation 2, ∀i∈[1,l),ci=min⁡(bi,bi+1)\forall i\in[1,l),c_i=\min(b_i,b_{i+1}).

Given an integer mm, you can perform operation 1 at most mm times. After performing n−1n-1 operations, the length of sequence aa becomes 11. You may arrange the order of operations arbitrarily. Find the maximum possible value of the final remaining number a1a_1.

Input Format

The first line contains two integers n,mn,m.

The second line contains nn integers aia_i, representing the initial sequence.

Output Format

Output one integer, representing the maximum possible value of the final remaining number.

4 2
1 2 3 3
3

Hint

Sample Explanation

One possible order of operations is:

  • Perform operation 1 once, and the sequence becomes 2,3,32,3,3.
  • Perform operation 2 once, and the sequence becomes 2,32,3.
  • Perform operation 1 once, and the sequence becomes 33.

Obviously, the final remaining number cannot be greater than 33.

Constraints

This problem uses bundled testdata.

Subtask\mathrm{Subtask} n≤n\le Special property Score
11 1010 1010
22 50005000 3030
33 10610^6 ✓\checkmark 2020
44 4040

Special property: it is guaranteed that ∀i∈[1,n],ai≤10\forall i\in[1,n],a_i\le10.

For all data, it is guaranteed that 1≤m<n≤1061\leq m < n \leq 10^6, and 1≤ai≤1091 \leq a_i \leq 10^{9}.

Translated by ChatGPT 5