CF977C.Less or Equal

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a sequence of integers of length nn and integer number kk. You should print any integer number xx in the range of [1;109][1; 10^9] (i.e. 1≤x≤1091 \le x \le 10^9) such that exactly kk elements of given sequence are less than or equal to xx.

Note that the sequence can contain equal elements.

If there is no such xx, print "-1" (without quotes).

给你一个长度为 nn 的整数序列以及一个整数 kk。你需要输出任意一个在区间 [1;109][1; 10^9](即 1≤x≤1091 \le x \le 10^9)内的整数 xx,使得给定序列中恰好有 kk 个元素小于等于 xx。

注意:该序列中可能包含相等的元素。

若不存在满足条件的 xx,则输出 \-1(不带引号)。

输入格式

The first line of the input contains integer numbers nn and kk (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5, 0≤k≤n0 \le k \le n). The second line of the input contains nn integer numbers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1091 \le a_i \le 10^9) — the sequence itself.

输入的第一行包含两个整数 nn 和 kk(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5,0≤k≤n0 \le k \le n)。
输入的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091 \le a_i \le 10^9)—— 即该序列本身。

输出格式

Print any integer number xx from range [1;109][1; 10^9] such that exactly kk elements of given sequence is less or equal to xx.

If there is no such xx, print "-1" (without quotes).

输出任意一个整数 xx(xx 需满足 1≤x≤1091 \le x \le 10^9),使得给定序列中恰好有 kk 个元素小于或等于 xx。

如果不存在这样的 xx,则输出 \-1(不带引号)。

输入输出样例

  • 输入#1

    7 4
    3 7 5 1 10 3 20

    输出#1

    6
  • 输入#2

    7 2
    3 7 5 1 10 3 20

    输出#2

    -1

说明/提示

In the first example 55 is also a valid answer because the elements with indices [1,3,4,6][1, 3, 4, 6] is less than or equal to 55 and obviously less than or equal to 66.

In the second example you cannot choose any number that only 22 elements of the given sequence will be less than or equal to this number because 33 elements of the given sequence will be also less than or equal to this number.

在第一个例子中,55 也是一个合法的答案,因为下标为 [1,3,4,6][1, 3, 4, 6] 的元素均小于等于 55,显然也小于等于 66。

在第二个例子中,你无法选择任何一个数,使得给定序列中恰好只有 22 个元素小于等于该数,因为对于任意这样的数,给定序列中将至少有 33 个元素小于等于它。

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

首页