Kth Smallest Element using heap
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
int main() {
priority_queue<int> maxh; //Max-Heap declaration
int n;
cin>>n;
int k;
cin>>k;
int A[n];
for(int i =0 ; i<n ; i++){
cin>>A[i];
}
for(int i =0 ; i<n ; i++){
maxh.push(A[i]);
if(maxh.size()>k){
maxh.pop();
}
}
cout<<maxh.top();
}INFO