博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Social Network (easy version) CodeForces - 1234B1(vector)
阅读量:4135 次
发布时间:2019-05-25

本文共 3277 字,大约阅读时间需要 10 分钟。

The only difference between easy and hard versions are constraints on nn and kk.

You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most kk most recent conversations with your friends. Initially, the screen is empty (i.e. the number of displayed conversations equals 00).

Each conversation is between you and some of your friends. There is at most one conversation with any of your friends. So each conversation is uniquely defined by your friend.

You (suddenly!) have the ability to see the future. You know that during the day you will receive nn messages, the ii-th message will be received from the friend with ID idiidi (1≤idi≤1091≤idi≤109).

If you receive a message from idiidi in the conversation which is currently displayed on the smartphone then nothing happens: the conversations of the screen do not change and do not change their order, you read the message and continue waiting for new messages.

Otherwise (i.e. if there is no conversation with idiidi on the screen):

Firstly, if the number of conversations displayed on the screen is kk, the last conversation (which has the position kk) is removed from the screen.

Now the number of conversations on the screen is guaranteed to be less than kk and the conversation with the friend idiidi is not displayed on the screen.
The conversation with the friend idiidi appears on the first (the topmost) position on the screen and all the other displayed conversations are shifted one position down.
Your task is to find the list of conversations (in the order they are displayed on the screen) after processing all nn messages.

Input

The first line of the input contains two integers nn and kk (1≤n,k≤200)1≤n,k≤200) — the number of messages and the number of conversations your smartphone can show.

The second line of the input contains nn integers id1,id2,…,idnid1,id2,…,idn (1≤idi≤1091≤idi≤109), where idiidi is the ID of the friend which sends you the ii-th message.

Output

In the first line of the output print one integer mm (1≤m≤min(n,k)1≤m≤min(n,k)) — the number of conversations shown after receiving all nn messages.

In the second line print mm integers ids1,ids2,…,idsmids1,ids2,…,idsm, where idsiidsi should be equal to the ID of the friend corresponding to the conversation displayed on the position ii after receiving all nn messages.

Examples

Input
7 2
1 2 3 2 1 3 2
Output
2
2 1
Input
10 4
2 3 3 1 1 2 1 2 3 3
Output
3
1 3 2
Note
In the first example the list of conversations will change in the following way (in order from the first to last message):

[][];

[1][1];
[2,1][2,1];
[3,2][3,2];
[3,2][3,2];
[1,3][1,3];
[1,3][1,3];
[2,1][2,1].
In the second example the list of conversations will change in the following way:

[][];

[2][2];
[3,2][3,2];
[3,2][3,2];
[1,3,2][1,3,2];
and then the list will not change till the end.
考验stl的两道题目。
第一个比较简单因为数据量小,用vector或者双端队列都可以。我用的vector。
代码如下:

#include
#define ll long longusing namespace std;const int maxx=2e2+10;vector
h;int n,m;int main(){
while(~scanf("%d%d",&n,&m)) {
h.clear(); int x; for(int i=1;i<=n;i++) {
scanf("%d",&x); vector
::iterator it=find(h.begin(),h.end(),x); if(it!=h.end()) continue; else {
if(h.size()

努力加油a啊,(o)/~

转载地址:http://eytvi.baihongyu.com/

你可能感兴趣的文章
DeepLearning tutorial(6)易用的深度学习框架Keras简介
查看>>
DeepLearning tutorial(7)深度学习框架Keras的使用-进阶
查看>>
流形学习-高维数据的降维与可视化
查看>>
Python-OpenCV人脸检测(代码)
查看>>
python+opencv之视频人脸识别
查看>>
人脸识别(OpenCV+Python)
查看>>
6个强大的AngularJS扩展应用
查看>>
网站用户登录系统设计——jsGen实现版
查看>>
第三方SDK:讯飞语音听写
查看>>
第三方SDK:JPush SDK Eclipse
查看>>
第三方开源库:imageLoader的使用
查看>>
自定义控件:飞入飞出的效果
查看>>
自定义控件:动态获取控件的高
查看>>
第三方开源库:nineoldandroid:ValueAnimator 动态设置textview的高
查看>>
第三方SDK:百度地图SDK的使用
查看>>
Android studio_迁移Eclipse项目到Android studio
查看>>
JavaScript setTimeout() clearTimeout() 方法
查看>>
CSS border 属性及用border画各种图形
查看>>
转载知乎-前端汇总资源
查看>>
JavaScript substr() 方法
查看>>