import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param a int整型一维数组 
     * @param n int整型 
     * @param K int整型 
     * @return int整型
     */
    public int findKth (int[] a, int n, int K) {
        // write code here
        Queue<Integer> queue = new PriorityQueue<>((a1, b1) -> b1 - a1);//利用队列PriorityQueue的默认排序功能,加上降序定义实现降序排序
        for(int i=0; i<n; i++){
            queue.offer(a[i]);
        }

        int j = 0;
        int target = -1;
        while(!queue.isEmpty() && j < K){
            target = queue.poll();
            j++;
        }

        return target;

    }
}