CodeForce977C - Less or EqualLess or Equal(思维有坑)

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).

Input

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.

Output

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).

Examples

Input

Copy

7 4
3 7 5 1 10 3 20

Output

Copy

6

Input

Copy

7 2
3 7 5 1 10 3 20

Output

Copy

-1

这个我主要卡在k=0时的情况了,我想错了;

其实k=0的时候不是只会输出-1;

例如数组里面都大于等于2,那么若k=0,则x可以是1;

若都大于等于1,min=1,则输出-1!!!!!!!!!!!

#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
int arr[N];
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=0; i<n; i++)
        scanf("%d",&arr[i]);
    sort(arr,arr+n);
    if(k==0)
    {
        int ans=arr[0]-1;//k=0时候有解,并不是都输出-1;
        if(ans<1) printf("-1\n");
        else printf("%d\n",ans);
    }
    else if(arr[k-1]==arr[k]) printf("-1\n");
    else printf("%d\n",arr[k-1]);
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值