#K6256. Top-K Posts Ranking
Top-K Posts Ranking
Top-K Posts Ranking
Given a list of posts, each containing a user identifier and an integer representing the number of likes, your task is to determine the top k posts with the most likes. The posts must be sorted primarily by the number of likes in non-increasing order. If two posts have the same number of likes, they should be ordered by the user identifier in alphabetical order.
Formally, let \(L_i\) be the number of likes for the \(i\)-th post and \(U_i\) be its user identifier. The posts are sorted such that for any two posts \(i\) and \(j\), if \(L_i > L_j\), or \(L_i = L_j\) and \(U_i .
Note: If \(k\) is greater than \(n\) (the total number of posts), output all posts.
inputFormat
The first line of input contains two integers: n and k, where n is the number of posts and k is the number of top posts to report. Each of the following n lines contains a string and an integer separated by a space, representing a user identifier and the number of likes.
outputFormat
Output exactly min(n, k) lines. Each line should contain the user identifier and the number of likes of a top post, separated by a space, in the sorted order as specified above.
## sample5 3
alice 100
bob 150
carol 100
dave 200
eve 150
dave 200
bob 150
eve 150
</p>