A13478 | Odd-Even Subsequence
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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$ .
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$ .
输入格式
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$ .
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 a single integer — the minimum cost of a subsequence of size $k$ .
输入输出样例
输入 #1
4 2 1 2 3 4
输出 #1
1
输入 #2
4 3 1 2 3 4
输出 #2
2
输入 #3
5 3 5 3 4 2 6
输出 #3
2
输入 #4
6 4 5 3 50 2 4 5
输出 #4
3
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$ .
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$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted