Less or Equal CodeForces

You are given a sequence of integers of length x.

Note that the sequence can contain equal elements.

If there is no such 

Input

The first line of the input contains integer numbers 1≤ai≤109) — the sequence itself.

Output

Print any integer number x.

If there is no such 

Examples

Input
7 4
3 7 5 1 10 3 20
Output
6
Input
7 2
3 7 5 1 10 3 20
Output
-1

Note

In the first example 6.

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

题意:

给你一个含有N个数组的数组,给你一个整数k,0<=k<=n 

让你输出一个数x,使之在这N个数中,有严格的k个数小于等于x。x的范围是1~1e9

思路:

排序后,如果a[k]!=a[k+1] 

输出a[k]就行了。

注意 下这几个坑点:

x的范围:1~1e9,

如果k是0,那么需要特判a[1] 是否是1

如果k为N,输出a[n]即可。

细节注意好就不会出错,。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d
",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), ' ', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/

ll n;
ll a[maxn];
int main()
{
    //freopen("D:\common_text\code_stream\in.txt","r",stdin);
    //freopen("D:\common_text\code_stream\out.txt","w",stdout);
    gbtb;
    cin>>n;
    ll k;
    cin>>k;
    repd(i,1,n)
    {
        cin>>a[i];
    }
    sort(a+1,a+1+n);
    if(k==0)
    {
        if(a[1]==1)
        {
            cout<<-1<<endl;
        }else
        {
            cout<<1<<endl;
        }
    }else
    {
        if(a[k]!=a[k+1])
        {
            if(a[k]<=1000000000)
                cout<<a[k]<<endl;
            else
            {
                cout<<-1<<endl;
            }
        }else
        {
            cout<<-1<<endl;
        }
    }
    
    
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '
');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}