#K2806. Sort Products by Discount
Sort Products by Discount
Sort Products by Discount
You are given a list of products along with their discount percentages. Your task is to sort the products in descending order based on the discount percentage. In case two products have the same discount percentage, their order should remain the same as the input order (i.e., the sort must be stable).
Formally, if we denote the discount percentage of the i-th product as \(d_i\), then the products must be ordered so that \(d_{i} \ge d_{j}\) for any product \(i\) that comes before product \(j\). The stability condition ensures that if \(d_i = d_j\) then the product coming first in the input remains first in the output.
inputFormat
The first line contains a single integer \(n\) denoting the number of products. The following \(n\) lines each contain a product's name (a string without spaces) and its discount percentage (an integer) separated by a space.
outputFormat
Output the sorted list of products, each on a new line, where each line contains the product name and the discount percentage separated by a space.
## sample5
Laptop 20
Headphones 50
Mouse 35
Keyboard 20
Monitor 50
Headphones 50
Monitor 50
Mouse 35
Laptop 20
Keyboard 20
</p>