Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main() {
- int n, k;
- cin >> n >> k;
- long long a[n];
- for (int i = 0; i < n; ++i) {
- cin >> a[i];
- }
- sort(a, a + n);
- if (k == 0) {
- cout << (a[0] == 1 ? -1 : 1);
- return 0;
- }
- if ((k < n && a[k] > a[k - 1]) || k == n) {
- cout << a[k - 1] << endl;
- } else {
- cout << -1 << endl;
- }
- }
Add Comment
Please, Sign In to add comment