IBMOA #28
Get Latest K Requests
估计简单可在线判题
考点(AI 标注)哈希计数
After receiving all requests, output the most recent k distinct request IDs, ordered from most recent to least recent by the last time each ID appeared. The original example makes clear that a repeated ID is reported only once. If there are fewer than k distinct IDs, this site's output convention is -1.
输入格式
The first line contains n k, followed by n lines of request IDs. On this site 1≤n,k≤100000, and each ID consists of 1 to 20 non-newline Unicode scalar characters and may contain spaces; read input line by line without trimming spaces.
输出格式
If there is no solution, output only -1; otherwise output k on the first line, followed by k lines of request IDs from most recent to least recent, with spaces preserved.
样例 1
输入:
5 3
item1
item2
item3
item1
item3
输出:
3
item3
item1
item2
样例 2
输入:
2 2
a
a
输出:
-1
样例 3
输入:
3 2
a b
a
a b
输出:
2
a b
a
样例说明
The examples output, line by line, 3, item3, item1, item2; -1; and 2, a b, a surrounded by spaces, respectively.