#K7181. Reorder Inventory

    ID: 33614 Type: Default 1000ms 256MiB

Reorder Inventory

Reorder Inventory

You are given an inventory list that contains items represented by a pair of integers: item_id and item_price. Your task is to reorder the inventory in descending order of the item price while preserving the original order among items with equal prices (i.e., the sorting must be stable). The reordering should be done in-place.

The sorting criteria are given as follows:

  • Items with a higher price should come first.
  • If two items have the same price, their relative order remains unchanged.

You are required to read the inventory from standard input and output the reordered inventory to standard output.

inputFormat

The input begins with an integer n representing the number of items in the inventory. The following n lines each contain two integers separated by a space: item_id and item_price.

For example:

4
1001 50
1002 40
1003 50
1004 60

outputFormat

Output the reordered inventory list to standard output, where each line contains the item_id and item_price separated by a single space. The inventory should be sorted in descending order of item price and, in case of ties, in the same order as the input.

For example, the output for the sample input above should be:

1004 60
1001 50
1003 50
1002 40
## sample
4
1001 50
1002 40
1003 50
1004 60
1004 60

1001 50 1003 50 1002 40

</p>