class Solution {
public:
vector<int> GetLeastNumbers_Solution(vector<int> input, int k) {
vector<int> max_heap;
if(k > input.size())
return max_heap;
for(int i = 0; i < input.size(); i++){
max_heap.push_back(input[i]);
push_heap(max_heap.begin(), max_heap.end(), [](int a, int b){
if(a < b)
return true;
return false;
});
if(max_heap.size() > k){
pop_heap(max_heap.begin(), max_heap.end(), [](int a, int b){
if(a < b)
return true;
return false;
});
max_heap.erase(max_heap.end()-1);
}
}
/*sort(max_heap.begin(), max_heap.end(), [](int a, int b){
if(a < b)
return true;
return false;
});*/
sort_heap(max_heap.begin(), max_heap.end());
return max_heap;
}
};