#P1370D. Odd-Even Subsequence
Odd-Even Subsequence
No submission language available for this problem.
Description
Ashish has an array of size .
A subsequence of is defined as a sequence that can be obtained from by deleting some elements (possibly none), without changing the order of the remaining elements.
Consider a subsequence of . He defines the cost of as the minimum between:
- The maximum among all elements at odd indices of .
- The maximum among all elements at even indices of .
Note that the index of an element is its index in , rather than its index in . The positions are numbered from . So, the cost of is equal to .
For example, the cost of is .
Help him find the minimum cost of a subsequence of size .
The first line contains two integers and () — the size of the array and the size of the subsequence.
The next line contains integers () — the elements of the array .
Output a single integer — the minimum cost of a subsequence of size .
Input
The first line contains two integers and () — the size of the array and the size of the subsequence.
The next line contains integers () — the elements of the array .
Output
Output a single integer — the minimum cost of a subsequence of size .
Samples
Note
In the first test, consider the subsequence = . Here the cost is equal to .
In the second test, consider the subsequence = . Here the cost is equal to .
In the fourth test, consider the subsequence = . Here the cost is equal to .