Advertisement
fahimkamal63

Kth smallest element

Apr 10th, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1. //  Kth smallest element
  2. #include<iostream>
  3. #include<algorithm>
  4. using namespace std;
  5. int main(){
  6.     int t; cin >> t;
  7.     while(t--){
  8.         int n; cin >> n;
  9.         int a[n], i;
  10.         for(i = 0; i < n; i++) cin >> a[i];
  11.         int k; cin >> k;
  12.         k--;
  13.         nth_element(a, a+k, a+n);
  14.         cout << a[k]<< endl;
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement