#K8416. Transaction Query Processing
Transaction Query Processing
Transaction Query Processing
This problem involves processing a sequence of commands that represent transactions and queries. You are given operations of two types:
- T X C: Record a transaction of amount X for customer C.
- Q L: Query to retrieve the top L customers by their total transaction amounts.
The total transaction amount for a customer \( c \) is denoted by \( T(c) \). Customers are ranked in descending order of \( T(c) \); in the event of a tie (i.e. when \( T(c_1) = T(c_2) \)), the customer with the smaller customer id is ranked higher.
inputFormat
The first line contains an integer \( Q \), the number of operations. Each of the next \( Q \) lines contains an operation in one of the following two formats:
- T X C — a transaction operation where X is the transaction amount and C is the customer id.
- Q L — a query operation asking for the top L customers.
outputFormat
For each query operation (i.e. each line starting with Q), output a single line containing the ids of the top L customers separated by a single space. If there are fewer than L customers available, output all the available customer ids.
## sample7
T 500 1
T 300 2
T 200 1
Q 2
T 400 3
Q 1
Q 3
1 2
1
1 3 2
</p>