#K54187. Sort Books by Category and ID

    ID: 29698 Type: Default 1000ms 256MiB

Sort Books by Category and ID

Sort Books by Category and ID

You are given a list of books. Each book is described by two integers: the category and an ID. Your task is to sort the books based on the following criteria:

  • Primary: Sort by book category in descending order.
  • Secondary: For books with the same category, sort by book ID in ascending order.

The sorted list should then be printed with each book record on a new line, where the category and the ID are separated by a single space.

Note: All formulas or expressions, if any, must be written in LaTeX format. For example, the sorting criteria can be expressed as: $$\text{Sort key} = (-\text{category}, \text{id})$$.

inputFormat

The first line contains an integer \(N\) representing the number of books.

The following \(N\) lines each contain two integers separated by a space: the book's category and its ID.

Example:

4
2 101
3 105
2 99
1 150

outputFormat

Output the sorted list of books. Each line should contain two integers: the category and the ID, separated by a space.

Example:

3 105
2 99
2 101
1 150
## sample
4
2 101
3 105
2 99
1 150
3 105

2 99 2 101 1 150

</p>