File size: 500 Bytes
14c9c2b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    long long k;
    if (!(cin >> n >> k)) return 0;

    vector<long long> a;
    a.reserve(1LL * n * n);

    long long x;
    for (long long i = 0; i < 1LL * n * n; ++i) {
        cin >> x;
        a.push_back(x);
    }

    if (k < 1 || k > (long long)a.size()) return 0;

    nth_element(a.begin(), a.begin() + (k - 1), a.end());
    cout << a[k - 1];

    return 0;
}