Advertisement
LEGEND2004

Less or Equal

Jul 18th, 2023
948
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5. #define pb push_back
  6.  
  7. signed main()
  8. {
  9.     int n , k;
  10.     cin >> n >> k;
  11.     vector<int> a(n);
  12.     for(int i = 0; i < n; i++)
  13.         cin >> a[i];
  14.  
  15.     sort(a.begin() , a.end());
  16.  
  17.     if(k == n){
  18.         cout << (int)1e9 << endl;
  19.         return 0;
  20.     }
  21.     if(!k){
  22.         cout << ((a[0] == 1) ? "-1" : "1") << endl;
  23.         return 0;
  24.     }
  25.     if(a[k - 1] == a[k]){
  26.         cout << "-1" << endl;
  27.         return 0;
  28.     }
  29.     cout << a[k - 1] << endl;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement