class Solution {
public:
    
    void swap(int &p, int &q){
        int temp = p;
        p = q;
        q = temp;
    }
    
    int adjust(vector<int> &a){
        int size = a.size();
        int big1 = -999;
        for(int i=size/2-1; i>=0; i--){
            if(a[i]<a[2*i]) swap(a[i], a[2*i]);
            if(2*i+1<size&&a[i]<a[2*i+1]) swap(a[i], a[2*i+1]);
        }
        big1 = a[0];
        swap(a[0], a[size-1]);
        a.pop_back();
        return big1;
    }
    
    int findKth(vector<int> a, int n, int K) {
        int size = a.size();
        int temp = -999;
        for(int i=0; i<K; i++){
            temp = adjust(a);
        }
        return temp;
    }
};