class Solution {
public:
    vector<int> GetLeastNumbers_Solution(vector<int> input, int k) {
        vector<int> ans;
        if(k<=0||k>input.size())return ans;
        priority_queue<int> pq; // 优先队列默认大根堆
        for(int val : input){
            if(pq.size()<k)pq.push(val);
            else if(val<pq.top())
            {
                pq.pop(); //最大值出队
                pq.push(val);
            }
        }
        while(!pq.empty()){
            ans.push_back(pq.top());
            pq.pop();
        }
        return ans;
    }
};