Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- #define pb push_back
- signed main()
- {
- int n , k;
- cin >> n >> k;
- vector<int> a(n);
- for(int i = 0; i < n; i++)
- cin >> a[i];
- sort(a.begin() , a.end());
- if(k == n){
- cout << (int)1e9 << endl;
- return 0;
- }
- if(!k){
- cout << ((a[0] == 1) ? "-1" : "1") << endl;
- return 0;
- }
- if(a[k - 1] == a[k]){
- cout << "-1" << endl;
- return 0;
- }
- cout << a[k - 1] << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement