CF977C.Less or Equal
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a sequence of integers of length n and integer number k. You should print any integer number x in the range of [1;109] (i.e. 1≤x≤109) such that exactly k elements of given sequence are less than or equal to x.
Note that the sequence can contain equal elements.
If there is no such x, print "-1" (without quotes).
给你一个长度为 n 的整数序列以及一个整数 k。你需要输出任意一个在区间 [1;109](即 1≤x≤109)内的整数 x,使得给定序列中恰好有 k 个元素小于等于 x。
注意:该序列中可能包含相等的元素。
若不存在满足条件的 x,则输出 \-1(不带引号)。
输入格式
The first line of the input contains integer numbers n and k (1≤n≤2⋅105, 0≤k≤n). The second line of the input contains n integer numbers a1,a2,…,an (1≤ai≤109) — the sequence itself.
输入的第一行包含两个整数 n 和 k(1≤n≤2⋅105,0≤k≤n)。
输入的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)—— 即该序列本身。
输出格式
Print any integer number x from range [1;109] such that exactly k elements of given sequence is less or equal to x.
If there is no such x, print "-1" (without quotes).
输出任意一个整数 x(x 需满足 1≤x≤109),使得给定序列中恰好有 k 个元素小于或等于 x。
如果不存在这样的 x,则输出 \-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 5 is also a valid answer because the elements with indices [1,3,4,6] is less than or equal to 5 and obviously less than or equal to 6.
In the second example you cannot choose any number that only 2 elements of the given sequence will be less than or equal to this number because 3 elements of the given sequence will be also less than or equal to this number.
在第一个例子中,5 也是一个合法的答案,因为下标为 [1,3,4,6] 的元素均小于等于 5,显然也小于等于 6。
在第二个例子中,你无法选择任何一个数,使得给定序列中恰好只有 2 个元素小于等于该数,因为对于任意这样的数,给定序列中将至少有 3 个元素小于等于它。
输入解题思路,AI测评打分。不知道怎么写?