forked from pankaj443/CODEFORCES
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path977C.cpp
More file actions
36 lines (35 loc) · 617 Bytes
/
Copy path977C.cpp
File metadata and controls
36 lines (35 loc) · 617 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1<<21;
vector<int>v;
ll cnt,a[N],b[N],has[N],n,m,sum,min1,max1;
string s,t;
bool flag;
int main()
{
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
cin>>n>>m;
for(ll i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
if(m==0)
{
if(a[0]==1)
cout<<"-1";
else{cout<<a[0]-1;}
}
else{
for(int i=0;i<n;i++)
{
if(a[m-1]!=a[m])
{if(a[m-1]>0)cout<<a[m-1];
else cout<<"-1";
break;}
else {cout<<"-1";break;}
}}
return 0;
}
//_4_4_3_//