#C2436. Most Popular Books by Genre
Most Popular Books by Genre
Most Popular Books by Genre
You are tasked with developing a feature for an online bookstore system to display the most popular book in each genre. Given (N), the number of books, and a list of books where each book is described by its genre, popularity score, and title, your goal is to determine for each genre the book that has the highest popularity score. In case of a tie in popularity for a genre, choose the book with the lexicographically smallest title. Finally, output the results sorted by genre in lexicographical order, with each line formatted as "genre title".
inputFormat
The input is read from standard input (stdin). The first line contains an integer (N) ((1 \le N \le 10^5)) representing the number of books. Each of the following (N) lines contains three space-separated values: a string denoting the genre, an integer for the popularity score, and a string for the title.
outputFormat
Output the result to standard output (stdout). For each genre present in the input, print a line containing the genre and the title of its most popular book, separated by a space. The genres must be printed in lexicographical order.## sample
5
fiction 100 foundation
nonfiction 200 sapiens
fiction 150 dune
fiction 100 hyperion
nonfiction 200 guns_germs_and_steel
fiction dune
nonfiction guns_germs_and_steel
</p>