CF1370D.Odd-Even Subsequence

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Ashish has an array aa of size nn.

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

Consider a subsequence ss of aa. He defines the cost of ss as the minimum between:

  • The maximum among all elements at odd indices of ss.
  • The maximum among all elements at even indices of ss.

Note that the index of an element is its index in ss, rather than its index in aa. The positions are numbered from 11. So, the cost of ss is equal to min(max(s1,s3,s5,…),max(s2,s4,s6,…))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{7, 5, 6} is min(max(7,6),max(5))=min(7,5)=5min( max(7, 6), max(5) ) = min(7, 5) = 5.

Help him find the minimum cost of a subsequence of size kk.

阿什什有一个长度为 nn 的数组 aa。

数组 aa 的一个子序列定义为:通过删除 aa 中某些元素(可能不删任何元素)而得到的序列,且剩余元素的相对顺序保持不变。

考虑 aa 的一个子序列 ss。他将 ss 的代价定义为以下两个值中的较小者:

  • ss 中所有位于奇数位置的元素的最大值;
  • ss 中所有位于偶数位置的元素的最大值。

注意:此处“位置”指该元素在子序列 ss 中的下标(从 11 开始编号),而非其在原数组 aa 中的下标。因此,ss 的代价等于

min⁡(max⁡(s1,s3,s5,…), max⁡(s2,s4,s6,…)).\min\big(\max(s_1, s_3, s_5, \ldots),\ \max(s_2, s_4, s_6, \ldots)\big).

例如,子序列 {7,5,6}\{7, 5, 6\} 的代价为

min⁡(max⁡(7,6), max⁡(5))=min⁡(7,5)=5.\min\big(\max(7, 6),\ \max(5)\big) = \min(7, 5) = 5.

请帮他找出长度恰好为 kk 的子序列的最小可能代价。

输入格式

The first line contains two integers nn and kk (2≤k≤n≤2⋅1052 \leq k \leq n \leq 2 \cdot 10^5) — the size of the array aa and the size of the subsequence.

The next line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \leq a_i \leq 10^9) — the elements of the array aa.

第一行包含两个整数 nn 和 kk(2≤k≤n≤2⋅1052 \leq k \leq n \leq 2 \cdot 10^5)—— 分别表示数组 aa 的大小和子序列的大小。

下一行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \leq a_i \leq 10^9)—— 表示数组 aa 的元素。

输出格式

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

输出一个整数——大小为 kk 的子序列的最小代价。

输入输出样例

  • 输入#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 ss = 1,3{1, 3}. Here the cost is equal to min(max(1),max(3))=1min(max(1), max(3)) = 1.

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

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

在第一个测试用例中,考虑子序列 ss = 1,3{1, 3}。此时代价为 min(max(1),max(3))=1min(max(1), max(3)) = 1。

在第二个测试用例中,考虑子序列 ss = 1,2,4{1, 2, 4}。此时代价为 min(max(1,4),max(2))=2min(max(1, 4), max(2)) = 2。

在第四个测试用例中,考虑子序列 ss = 3,50,2,4{3, 50, 2, 4}。此时代价为 min(max(3,2),max(50,4))=3min(max(3, 2), max(50, 4)) = 3。

输入解题思路,AI测评打分。不知道怎么写?

首页