Codeforces Round 651 (Div. 2)
D
Odd-Even Subsequence
Codeforces
2000
原题
← CE →
翻译中…

Ashish has an array $a$ of size $n$.

翻译中…

A subsequence of $a$ is defined as a sequence that can be obtained from $a$ by deleting some elements (possibly none), without changing the order of the remaining elements.

翻译中…

Consider a subsequence $s$ of $a$. He defines the cost of $s$ as the minimum between:

翻译中…
  • The maximum among all elements at odd indices of $s$.
  • The maximum among all elements at even indices of $s$.
翻译中…

Note that the index of an element is its index in $s$, rather than its index in $a$. The positions are numbered from $1$. So, the cost of $s$ is equal to $min(max(s_1, s_3, s_5, \ldots), max(s_2, s_4, s_6, \ldots))$.

翻译中…

For example, the cost of $\{7, 5, 6\}$ is $min( max(7, 6), max(5) ) = min(7, 5) = 5$.

翻译中…

Help him find the minimum cost of a subsequence of size $k$.

翻译中…

Input

翻译中…

The first line contains two integers $n$ and $k$ ($2 \leq k \leq n \leq 2 \cdot 10^5$)  — the size of the array $a$ and the size of the subsequence.

翻译中…

The next line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)  — the elements of the array $a$.

翻译中…

Output

翻译中…

Output a single integer  — the minimum cost of a subsequence of size $k$.

翻译中…

Note

翻译中…

In the first test, consider the subsequence $s$ = $\{1, 3\}$. Here the cost is equal to $min(max(1), max(3)) = 1$.

翻译中…

In the second test, consider the subsequence $s$ = $\{1, 2, 4\}$. Here the cost is equal to $min(max(1, 4), max(2)) = 2$.

翻译中…

In the fourth test, consider the subsequence $s$ = $\{3, 50, 2, 4\}$. Here the cost is equal to $min(max(3, 2), max(50, 4)) = 3$.

翻译中…

样例

Input #1
4 2
1 2 3 4
Output #1
1
InputCopy OutputCopy
Input #2
4 3
1 2 3 4
Output #2
2
InputCopy OutputCopy
Input #3
5 3
5 3 4 2 6
Output #3
2
InputCopy OutputCopy
Input #4
6 4
5 3 50 2 4 5
Output #4
3
InputCopy OutputCopy
题目信息
题号
1370D
时间限制
2 s
内存限制
256 MB
标签
二分
动态规划
并查集
贪心
模拟

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