-
Notifications
You must be signed in to change notification settings - Fork 39
/
Prizes.cpp
49 lines (41 loc) · 828 Bytes
/
Prizes.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <bits/stdc++.h>
using namespace std;
vector<int> solve(vector<int>& nums, int k) {
unordered_map<int,int> numMap;
for (auto &n : nums) {
numMap[n]++;
}
priority_queue<pair<int,int>> q;
for (auto &i : numMap) {
q.push(make_pair(-i.second,i.first));
if (q.size() > k) q.pop();
}
vector<int> result;
while(!q.empty()) {
result.push_back(q.top().second);
q.pop();
}
return result;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n,k;
cin>>n>>k;
vector<int> v;
int x;
for(int i=0;i<n;i++)
{
cin>>x;
v.push_back(x);
}
v=solve(v,k);
for(int i=0;i<v.size();i++)
cout<<v[i]<<" ";
cout<<endl;
}
return 0;
}