#C12046. Taco Book Sorting
Taco Book Sorting
Taco Book Sorting
You are given a collection of books. Each book has a unique identifier and an associated popularity score. Your task is to sort the books according to the following criteria:
- Books should be sorted in descending order of their popularity score.
- If two books have the same popularity score, they should be sorted in ascending order of their identifier.
Mathematically, if we denote each book as a tuple \((id, score)\), the sorting order is defined as follows: $$ (a, b) \prec (c, d) \quad \text{if and only if} \quad \Big( b > d \Big) \; \text{or} \; \Big( b = d \; \text{and} \; a < c \Big). $$
The input is provided via stdin
and the output must be printed to stdout
.
inputFormat
The first line contains an integer n
representing the number of books.
The next n
lines each contain two integers separated by a space: the identifier
and the popularity score
of a book.
Example:
5 1 10 2 20 3 20 4 5 5 10
outputFormat
Output the sorted list of books, one book per line. Each line should contain the identifier
and popularity score
separated by a space in the order defined by the problem statement.
Example Output:
2 20 3 20 1 10 5 10 4 5## sample
5
1 10
2 20
3 20
4 5
5 10
2 20
3 20
1 10
5 10
4 5
</p>