#K33887. Best Selling Product
Best Selling Product
Best Selling Product
You are given a list of transactions. Each transaction contains a product ID (a string) and the number of units sold (an integer). Your task is to determine the product that has sold the most units in total. In case of a tie, output the product ID that comes first in lexicographical order.
Formally, if there are N transactions and the i-th transaction is represented as \( (p_i, q_i) \) where \( p_i \) is the product ID and \( q_i \) is the number of units sold, then you need to find the product \( P \) such that:
[ P = \min_{p_i \in S} ; p_i\quad \text{ where }; S = { p_i \mid \sum_{p_j=p_i} q_j = Q_{\max} },]
and \( Q_{\max} = \max_{p_i} \sum_{p_j=p_i} q_j \). The answer should be printed to the standard output.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains a single integer N representing the number of transactions.
- The following N lines each contain a string and an integer separated by space, representing the product ID and the quantity sold in that transaction.
outputFormat
Output a single line to the standard output (stdout) containing the product ID of the best selling product.
## sample1
abc123 150
abc123
</p>