Solution of 'Less or Equal' (Codeforces)

 Hey guys! Here's my solution of question-'Less or Equal' from Codeforces. I am looking forward to your suggestions for my code or blog. So do comment. TY and Happy coding!

question link: https://codeforces.com/contest/977/problem/C

#include <bits/stdc++.h>
#define pair <int,int> pp
using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    vector<intvec;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        vec.push_back(x);
    }
    sort(vec.begin(),vec.end());
    if((k!=0)&&(vec[k-1]!=vec[k])) {cout<<vec[k-1];}
    else if((k==0)&&vec[k]!=1){cout<<vec[k]-1;}
    else{
        cout<<-1;
    }
}

Comments

Popular posts from this blog

Solution of 'The Two Dishes' (Codechef)

Solution of 'Tom Riddle's Diary' (Codeforces)

Solution to the problem 'Red Light, Green Light' from Codechef