#BS0000354. Dãy con chẵn lẻ (Odd-Even Subsequence)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Dãy con chẵn lẻ (Odd-Even Subsequence)
Odd-Even Subsequence
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Ashish has an integer sequence of length . A subsequence is formed by deleting zero or more entries while retaining the order of the remaining entries.
Consider a subsequence of length exactly , numbered from through . Let and be the largest entries at odd and even positions of , respectively. Its cost is . Both groups are nonempty because .
Determine the minimum cost among all such subsequences. Parity refers to positions in , not the original array.
Input
The first line contains integers , the original length and required subsequence length.
The second line contains integers in their original order.
Output
Print one integer: the minimum cost.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input 1
4 2
1 2 3 4
Output 1
1
Explanation
Choose , whose odd and even maxima are and . Its cost is , a lower bound because all entries are at least .
Input 2
4 3
1 2 3 4
Output 2
2
Explanation
Choose , with maxima and . A cost of would require two entries at most in odd positions or a in the middle. The sole is first in the original array, ruling out both.
Input 3
5 3
5 3 4 2 6
Output 3
2
Explanation
Choose ; the maxima are and . No smaller cost is possible because all entries are at least .
Input 4
6 4
5 3 50 2 4 5
Output 4
3
Explanation
Choose , giving maxima and . A cost below requires two entries at most in one parity group, but only one exists.