Memorizing English Words Is Painful
InterviewTime limit1sMemory limit1024 MB
Count each word of length at least M, then sort the distinct words by frequency descending, length descending, and alphabetical order.
- Level
Medium4 of 10
- Topics
- Hash map, Sorting, String, Implementation
- Solved
- No attempts yet
Problem
Hwa-eun wants to memorize English words based on the questions she got wrong on her English exam. She is going to make a vocabulary notebook to memorize English words efficiently. The order of words in the notebook is determined by applying the following priorities in order.
- Words that appear more often come first.
- Words with greater length come first.
- Words that come earlier in alphabetical order come first.
Words shorter than can be memorized just by reading them, so she only memorizes words of length at least . Let us make a vocabulary notebook so that Hwa-eun can memorize English words efficiently.
Input
The first line gives the number of words in the English passage and the length threshold for words to memorize, separated by a space. (, )
From the second line to the -th line, the words to memorize are given. Each word consists only of lowercase English letters and its length does not exceed .
Only inputs for which the notebook contains at least one word are given.
Output
Print the words in Hwa-eun's notebook in order, starting from the word at the front of the notebook, one word per line.
Hint
You can make input and output faster by doing the following.
- If you use C++ and want to use
cin/cout, apply bothcin.tie(NULL)andsync_with_stdio(false), and use the newline character (\n) instead ofendl. However, once you do this, you must no longer use C input/output functions such asscanf/printf/puts/getchar/putchar. - If you use Java, you can use
BufferedReaderandBufferedWriterinstead ofScannerandSystem.out.println. CallBufferedWriter.flushonly once, at the very end. - If you use Python, you can use
sys.stdin.readlineinstead ofinput. However, since this reads the trailing newline character as well, it is better to add.rstrip()when you want to store the string. Finally, Pypy3 has the same syntax as Python 3 and generally runs faster. If you want to use Python on a problem with a large amount of computation, submitting with Pypy is recommended.