C. Less or Equal
C.减少或平等
time limit per test: 2 seconds
time limit per test: 2 seconds
memory limit per test: 256 megabytes
每次测试的内存限制:256兆字节
input: standard input
输入:标准输入
output: standard output
产出:标准产出
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]
给你一个长度n和整数k的整数序列。你应该在[1;109]范围内打印任何整数x。
(ie.1≤x≤109) such that exactly k elements of given sequence are less than or equal to x.
(ie.1≤x≤109)使给定序列的精确k元素小于或等于x。
Note that the sequence can contain equal elements.
注意,序列可以包含相同的元素。
If there is no such x, print “-1” (without quotes).
如果没有这样的x,打印“-1”(没有引号)。
Input
输入
The first line of the input contains integer numbers n andk(1 < n≤2.10*,0< k< n). The second line of the input contains n
输入的第一行包含整数n和k(1<n≤2.10*,0<k<n)。输入的第二行包含n。
integer numbers a,a…,an(1≤ai≤109)- the sequence itelf.
整数a,a.,an(1≤ai≤109)-序列本身。
Output
输出量
Print any integer number x from range [1; 109] such that exactly k elements of given sequence is less or equal to x.
从范围[1;109]打印任意整数x,使给定序列中的k个元素小于或等于x。
If there is no such x, print “-1” (without quotes).
如果没有这样的x,打印“-1”(没有引号)。
模拟
int main( )
{
int n,k;
int a[200010];
cin >> n >> k;
for(int i = 0;i < n;++i)
cin >> a[i];
sort(a,a+n);
if(k==n)cout << a[n-1] <<endl;
else if(k==0){
if(a[0] == 1)
cout << "-1" <<endl;
else
cout << "1" <<endl;
}
else{
if(a[k]>a[k-1])
cout << a[k-1] << endl;
else
cout << "-1" <<endl;
}
return 0;
}