#C8005. Top Spenders

    ID: 51940 Type: Default 1000ms 256MiB

Top Spenders

Top Spenders

You are given T purchase records and an integer N. Each purchase record consists of a customer ID, a product name, and the price paid. Your task is to identify the top N spenders, i.e. the customers who have spent the most in total.

The total spending for a customer is defined as \( \text{total} = \sum_{i=1}^{T} price_i \) over all records for that customer. In the event of a tie (customers with the same total spending), the customer with the lexicographically smaller ID should come first.

The input is provided via stdin and your program should output the result to stdout. Each line of the output should contain the customer ID and the total spending (rounded to two decimal places), separated by a single space.

inputFormat

The first line contains an integer T (the number of purchase records). The next T lines each contain a string customer_id, a string product_name, and a floating-point number price separated by spaces. The last line contains an integer N, the number of top spenders to output.

Example:

6
C001 shoes 99.99
C002 dress 49.95
C001 bag 199.99
C003 shoes 99.99
C002 shoes 150.00
C003 dress 200.00
2

outputFormat

Output exactly N lines. Each line should contain a customer_id and the corresponding total spending (rounded to two decimal places) separated by a space. The customers should be listed in descending order of total spending. If multiple customers have the same total spending, they should be sorted in ascending order by their customer_id.

Example:

C003 299.99
C001 299.98
## sample
6
C001 shoes 99.99
C002 dress 49.95
C001 bag 199.99
C003 shoes 99.99
C002 shoes 150.00
C003 dress 200.00
2
C003 299.99

C001 299.98

</p>