#include <stdio.h>
#include <string.h>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;
struct node
{
int v;
int ans;
bool operator < (const node &a) const
{
if(ans!=a.ans)return ans>a.ans;
else return v<a.v;
}
node(int _v,int _ans)
{
v=_v;
ans=_ans;
}
};
set<node> st;
int c[51000];
int N,K;
int main()
{
scanf("%d%d",&N,&K);
for(int i=0;i<N;i++)
{
int item;
scanf("%d",&item);
if(st.size()!=0)
{
printf("%d:",item);
int step=0;
for(set<node>::iterator it=st.begin();it!=st.end()&&step<K;it++,step++)
{
printf(" %d",it->v);
}
printf("\n");
}
c[item]++;
node pre(item,c[item]-1);
node now(item,c[item]);
if(st.find(pre)!=st.end())
{
st.erase(st.find(pre));
}
st.insert(now);
}
return 0;
}
PAT甲1129 Recommendation System(25 分)
最新推荐文章于 2020-03-30 10:51:07 发布