#include <iostream>
#include <queue>
#include <vector>
#include <functional>
using namespace std;
vector<int> GetLeastNumber(vector<int> input, int k)
{
vector<int> res;
if (k <= 0 || k > input.size())
return res;
priority_queue<int> q; //默认是大顶堆
unsigned int i = 0;
while (i < input.size())
{
q.push(input[i]);
if (q.size() > k)
q.pop();
++i;
}
while (!q.empty())
{
res.push_back(q.top());
q.pop();
}
return res;
}
bool cmp(int a, int b)
{
return a < b;
}
vector<int> GetBiggerNumber(vector<int> input, int k)
{
vector<int> res;
if (k <= 0 || k > input.size())
return res;
priority_queue<int, vector<int>, greater<int> > q;
unsigned int i = 0;
while (i < input.size())
{
q.push(input[i]);
if (q.size() > k)
q.pop();
++i;
}
while (!q.empty())
{
res.push_back(q.top());
q.pop();
}
return res;
}
int main()
{
vector<int> input = { 1, 2, 3, 4, 7, 9, 8 ,0, 5 };
vector<int> arr(GetLeastNumber(input, 3));
for (auto i : arr)
cout << i << '\t';
cout << endl;
vector<int> arr1(GetBiggerNumber(input, 3));
for (auto i : arr1)
cout << i << '\t';
}