#C160. Top K Programming Languages
Top K Programming Languages
Top K Programming Languages
Given a survey of programming language votes, your task is to determine the top k programming languages with the most votes. The result must be sorted primarily by the number of votes in descending order. In case of a tie, the languages should be sorted in alphabetical order.
Formally, let \(f(\ell)\) be the number of votes for language \(\ell\). You are required to output the list of languages sorted by \(-f(\ell)\) and then by \(\ell\) in lexicographical order. For example, if there is a tie, a language \(A\) comes before \(B\) if \(A < B\) alphabetically.
inputFormat
The input is given in two lines:
- The first line contains two space-separated integers: (n) (the number of survey responses) and (k) (the number of top languages to return).
- If (n > 0), the second line contains (n) space-separated strings, each representing a programming language vote.
It is guaranteed that (k) is at least 1 and at most the number of distinct languages in the survey.
outputFormat
Output the top (k) programming languages, each on a separate line, in the order specified. The first line of the output should contain the language with the highest vote count, and so on.## sample
7 2
Python Java Python C++ Java Python JavaScript
Python
Java
</p>