306667: CF1234B1. Social Network (easy version)

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Social Network (easy version)

题意翻译

## 题目描述 你知道了将来N次给你发送的消息,而聊天软件一次性只能显示与K(1≤K≤200)个人的聊天记录。 当收到一条消息时,如果与这个人的聊天记录显示在聊天软件中,就什么都不做(注意,不需要把当前聊天记录置顶);否则,如果当前已经显示了K个聊天记录,则删除最后一个聊天记录;添加与这个人的聊天记录在列表顶端,同时其他聊天记录下移一个位置。 询问在这N条消息发送之后,你的聊天软件最终会显示与哪几个人的聊天记录。 ## 输入格式 第一行两个正整数N,K(1≤N,K≤200),表示N条发来的消息和一次性显示的聊天记录个数。 接下来一行N个正整数id[i] (1≤id[i]≤200),为第i条消息的发送者。 ## 输出格式 第一行,输出最后屏幕上显示的聊天记录个数X。 接下来一行X个正整数,按顺序输出最后屏幕上显示的聊天记录的对象。

题目描述

The only difference between easy and hard versions are constraints on $ n $ and $ k $ . You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most $ k $ most recent conversations with your friends. Initially, the screen is empty (i.e. the number of displayed conversations equals $ 0 $ ). 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 $ n $ messages, the $ i $ -th message will be received from the friend with ID $ id_i $ ( $ 1 \le id_i \le 10^9 $ ). If you receive a message from $ id_i $ 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 $ id_i $ on the screen): - Firstly, if the number of conversations displayed on the screen is $ k $ , the last conversation (which has the position $ k $ ) is removed from the screen. - Now the number of conversations on the screen is guaranteed to be less than $ k $ and the conversation with the friend $ id_i $ is not displayed on the screen. - The conversation with the friend $ id_i $ 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 $ n $ messages.

输入输出格式

输入格式


The first line of the input contains two integers $ n $ and $ k $ ( $ 1 \le n, k \le 200) $ — the number of messages and the number of conversations your smartphone can show. The second line of the input contains $ n $ integers $ id_1, id_2, \dots, id_n $ ( $ 1 \le id_i \le 10^9 $ ), where $ id_i $ is the ID of the friend which sends you the $ i $ -th message.

输出格式


In the first line of the output print one integer $ m $ ( $ 1 \le m \le min(n, k) $ ) — the number of conversations shown after receiving all $ n $ messages. In the second line print $ m $ integers $ ids_1, ids_2, \dots, ids_m $ , where $ ids_i $ should be equal to the ID of the friend corresponding to the conversation displayed on the position $ i $ after receiving all $ n $ messages.

输入输出样例

输入样例 #1

7 2
1 2 3 2 1 3 2

输出样例 #1

2
2 1 

输入样例 #2

10 4
2 3 3 1 1 2 1 2 3 3

输出样例 #2

3
1 3 2 

说明

In the first example the list of conversations will change in the following way (in order from the first to last message): - $ [] $ ; - $ [1] $ ; - $ [2, 1] $ ; - $ [3, 2] $ ; - $ [3, 2] $ ; - $ [1, 3] $ ; - $ [1, 3] $ ; - $ [2, 1] $ . In the second example the list of conversations will change in the following way: - $ [] $ ; - $ [2] $ ; - $ [3, 2] $ ; - $ [3, 2] $ ; - $ [1, 3, 2] $ ; - and then the list will not change till the end.

Input

题意翻译

## 题目描述 你知道了将来N次给你发送的消息,而聊天软件一次性只能显示与K(1≤K≤200)个人的聊天记录。 当收到一条消息时,如果与这个人的聊天记录显示在聊天软件中,就什么都不做(注意,不需要把当前聊天记录置顶);否则,如果当前已经显示了K个聊天记录,则删除最后一个聊天记录;添加与这个人的聊天记录在列表顶端,同时其他聊天记录下移一个位置。 询问在这N条消息发送之后,你的聊天软件最终会显示与哪几个人的聊天记录。 ## 输入格式 第一行两个正整数N,K(1≤N,K≤200),表示N条发来的消息和一次性显示的聊天记录个数。 接下来一行N个正整数id[i] (1≤id[i]≤200),为第i条消息的发送者。 ## 输出格式 第一行,输出最后屏幕上显示的聊天记录个数X。 接下来一行X个正整数,按顺序输出最后屏幕上显示的聊天记录的对象。

加入题单

算法标签: