Odd-Even Subsequence

TimeLimit:2000MS  MemoryLimit:256MB
64-bit integer IO format:%I64d
未提交 | 登录后收藏
Problem Description

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(s1,s3,s5,…),max(s2,s4,s6,…)).


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≤k≤n≤2⋅10^5)  — the size of the array a and the size of the subsequence.


The next line contains n integers a1,a2,…,an (1≤ai≤10^9)  — the elements of the array a.


Output

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

SampleInput 1
4 2
1 2 3 4
SampleOutput 1
1
SampleInput 2
4 3
1 2 3 4
SampleOutput 2
2
SampleInput 3
5 3
5 3 4 2 6
SampleOutput 3
2
SampleInput 4
6 4
5 3 50 2 4 5
SampleOutput 4
3
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.

Submit
题目统计信息详细
总AC数4
通过人数4
尝试人数4
总提交量5
AC率80.00%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: