#C7715. Best Selling Products
Best Selling Products
Best Selling Products
Given multiple test cases, each containing a series of products and their sold quantities, your task is to determine the product with the highest total sales for each test case. If there is a tie for the maximum sales, choose the product with the lexicographically smallest name.
More formally, for each test case, you are given an integer representing the number of test cases. For each test case, the first integer indicates the number of records, followed by lines. Each line contains a product name and a positive integer, representing the quantity sold. Your goal is to calculate the product with the maximum total sales. In case of ties, output the product with the smallest lexicographical order.
inputFormat
Input is read from standard input (STDIN). The first line contains a single integer , the number of test cases. For each test case, the first line contains an integer , the number of records. Each of the next lines contains a string and an integer separated by a space, representing the product name and the sold quantity respectively.
outputFormat
For each test case, output a single line on standard output (STDOUT) containing the product name with the highest total sales. If multiple products have the same total sales, output the one that comes first in lexicographical order.## sample
2
3
apple 50
banana 75
cherry 75
4
notebook 100
pen 100
pencil 50
eraser 75
banana
notebook
</p>