977C Codeforces - Less or Equal




Solution in  c++

#include <bits/stdc++.h>

using namespace std;
int n,m,cnt=1;

int main()
{

    cin>>n>>m;
    int nn[n];
    for(int i=0;i<n;i++)
    cin>>nn[i];
    sort(nn,nn+n);
    cnt=m;

    if(m==0 && nn[0]>1){cout<<1;return 0;}
    else if(m==0 && nn[0]==1) {cout<<-1;return 0;}

    if(nn[cnt]==nn[cnt-1])
    {cout<<-1;return 0;}
    else cout<<nn[cnt-1];

    return 0;
}

Share on Google Plus

About Mohamed Sobhi

My name is Mo.Sobhy ,I study at School excelling high school in Ain Shams ,Cairo
My hobbies is programming ,and web development ,playing chess and writing horror stories.
    Blogger Comment
    Facebook Comment

0 التعليقات:

إرسال تعليق