#C7765. Highest Revenue Item
Highest Revenue Item
Highest Revenue Item
You are given T test cases. In each test case, you have a list of sales records. Each record consists of an item name and an associated revenue. Your task is to determine the item with the highest total revenue in each test case. The total revenue for an item is computed as the sum of its revenues over all records. Formally, for each item, compute $$R(item)=\sum_i revenue_i.$$ You should output the item for which \(R(item)\) is maximized. In the event of a tie, output the item which is lexicographically smallest.
Note: The input is provided via standard input (stdin
) and the output should be printed to standard output (stdout
).
inputFormat
The input begins with an integer T denoting the number of test cases. For each test case:
- The first line contains an integer N, the number of sales records.
- The following N lines each contain a string and an integer, representing an item name and its revenue, respectively.
You are required to process all test cases.
outputFormat
For each test case, output a single line containing the name of the item with the highest total revenue. If more than one item has the same highest revenue, output the lexicographically smallest item.
## sample2
4
apple 100
banana 200
apple 300
banana 200
3
laptop 4000
laptop 3000
mobile 8000
apple
mobile
</p>