CF1234B1.Social Network (easy version)

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 idiid_i ( 1idi1091 \le id_i \le 10^9 ).

If you receive a message from idiid_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 idiid_i 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 idiid_i is not displayed on the screen.
  • The conversation with the friend idiid_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 nn messages.

输入格式

The first line of the input contains two integers nn and kk ( 1n,k200)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 nn integers id1,id2,,idnid_1, id_2, \dots, id_n ( 1idi1091 \le id_i \le 10^9 ), where idiid_i is the ID of the friend which sends you the ii -th message.

输出格式

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

In the second line print mm integers ids1,ids2,,idsmids_1, ids_2, \dots, ids_m , where idsiids_i should be equal to the ID of the friend corresponding to the conversation displayed on the position ii after receiving all nn 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][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.
首页