One #include <iostream> #include <cstdio> using namespace std; int n, k; int t[5000010]; void findk(int l, int r){ int i = l, j = r, mid = t[(l+r)/2]; do { while (t[i] < mid) i++; while (t[j] > mid) j--; if (i <= j){ swap(t[i], t[j]); i++; j--; } } while (i <= j); if (k <= j) findk(l, j); else if (k >= i) findk(i, r); else cout << t[j+1]; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); cin >> n >> k; for (int i = 0; i < n; i++) cin >> t[i]; findk(0, n-1); return 0; } Two #include <iostream> #include <string> #include <algorithm> using namespace std; int t[5000010]; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); int n, k, tmp; cin >> n >> k; for(int i = 0; i < n; i++) cin >> t[i]; nth_element(t, t+k, t+n); cout << t[k]; return 0; }