QOJ.ac

QOJ

時間限制: 3 s 記憶體限制: 1024 MB 總分: 100

#1979. 感恩

统计

Ben 听说 Emmons 和 McCullough 的研究表明,有意识地练习感恩会对人们的幸福感产生持久的影响。由于他也想变得快乐,他决定在每天结束时回顾过去的一天,并写下三件他感激的事情,每行一件。在练习了 $N$ 天后,他很想知道哪些事情在他的清单上出现得最频繁。请帮助 Ben 找出他最常感激的 $K$ 件事。

输入格式

输入的第一行包含两个空格分隔的整数 $N$ 和 $K$。 接下来有 $3N$ 行,包含 Ben 在 $N$ 天里的记录。你可以假设对应同一天的三行内容互不重复。也就是说,如果你将输入划分为 $N$ 个包含 3 个连续行的块,则每个块中不包含两个相同的行。

输出格式

输出应表示 Ben 感激的事项列表,按在 Ben 的清单中出现的频率排序(出现频率最高的事项在前)。如果两个事项的出现频率相同,则最近出现的事项应排在前面。也就是说,在出现次数相同的情况下,最后一次出现时间较晚的事项应在输出中排在前面。最后,如果 Ben 的清单中有超过 $K$ 个不同的事项,你的输出应仅包含按要求排序后的前 $K$ 个事项。

数据范围

  • $1 \leqslant K \leqslant 3N \leqslant 100\,000$
  • 每行输入最多包含 50 个 (ASCII) 字符。

样例

样例输入 1

2 2
Supportive parents
Being able to solve a hard problem
Good food
Fun game with friends
Good food
Being healthy

样例输出 1

Good food
Being healthy

说明 1

Good food 是唯一在 Ben 的清单中出现两次的事项,因此它应该首先出现在输出中。所有其他事项在输入中仅出现一次,但 Being healthy 因为是最近出现的,所以优先排在前面。

样例输入 2

2 6
Supportive parents
Being able to solve a hard problem
Good food
Fun game with friends
Good food
Being healthy

样例输出 2

Good food
Being healthy
Fun game with friends
Being able to solve a hard problem
Supportive parents

说明 2

这里 Ben 感激的事项只有 5 个不同的,因此输出只有 5 行。在这个列表中,Good food 排在输出的第一位,因为它在输入中出现了两次,而其他事项则按在 Ben 清单中的最后出现时间排序。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.