#C5317. Sort Transactions

    ID: 48953 Type: Default 1000ms 256MiB

Sort Transactions

Sort Transactions

This problem requires sorting a list of transactions. Each transaction is represented by a pair of integers: a timestamp and a transaction amount. The goal is to sort the transactions based on two criteria:

  • Sort by timestamp in ascending order.
  • For transactions with the same timestamp, sort by transaction amount in descending order.

Mathematically, for two transactions \((t_a, a_a)\) and \((t_b, a_b)\), transaction A should come before transaction B if either:

  • \(t_a < t_b\), or
  • \(t_a = t_b\) and \(a_a > a_b\).

You are required to implement a solution that reads from standard input and writes the sorted transactions to standard output.

inputFormat

The input begins with an integer n, the number of transactions. This is followed by n lines, each containing two space-separated integers representing the timestamp and the transaction amount.

outputFormat

Output the sorted transactions, one per line. Each transaction should be printed as two space-separated integers: the timestamp and the transaction amount.## sample

5
1001 500
1002 800
1001 200
1002 400
1003 700
1001 500

1001 200 1002 800 1002 400 1003 700

</p>