#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k;
cin>>n>>k;
int a[n];
unordered_map<int,int> freq;
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> minhp;
for(int i=0;i<n;i++){
cin>>a[i];
freq[a[i]]++;
}
for(auto i=freq.begin();i!=freq.end();i++){
minhp.push({i->second,i->first});
if(minhp.size()>k){
minhp.pop();
}
}
while (minhp.size()>0){
cout<<minhp.top().second<<" ";
minhp.pop();
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: