islomiddin

479_C

May 6th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4. int main() {
  5.     int n, k;
  6.     cin >> n >> k;
  7.     long long a[n];
  8.     for (int i = 0; i < n; ++i) {
  9.         cin >> a[i];
  10.     }
  11.     sort(a, a + n);
  12.     if (k == 0) {
  13.         cout << (a[0] == 1 ? -1 : 1);
  14.         return 0;
  15.     }
  16.     if ((k < n && a[k] > a[k - 1]) || k == n) {
  17.         cout << a[k - 1] << endl;
  18.     } else {
  19.         cout << -1 << endl;
  20.     }
  21. }
Add Comment
Please, Sign In to add comment