#C7596. Best Selling Products
Best Selling Products
Best Selling Products
Problem Statement:
You are given one or more datasets containing transaction details. Each dataset starts with an integer (n) denoting the number of transactions, followed by (n) lines, each containing three integers (p), (q), and (r). Here, (p) is the product ID, (q) is the quantity sold, and (r) is the price per unit. The income for a transaction is computed as (q \times r). For each dataset, you are to find the product that generates the maximum total income. In the event of a tie (i.e. multiple products having the same total income), choose the product with the smallest ID.
Input Format: The input consists of one or more datasets. Each dataset begins with an integer (n) and is followed by (n) lines of transaction records. Datasets are possibly separated by blank lines.
Output Format: For each dataset, output the best-selling product ID. All product IDs for different datasets should be printed on a single line and separated by a space.
Note: Use standard input (stdin) for input and standard output (stdout) for output.
inputFormat
Input:
The input consists of several datasets. Each dataset begins with an integer (n) specifying the number of transactions. The following (n) lines each contain three integers representing the product id, quantity sold, and price per unit respectively. Datasets may be separated by blank lines.
outputFormat
Output:
Output a single line containing the best-selling product IDs for each dataset separated by a space. For a given dataset, the best-selling product is the one with the maximum total income. In case of a tie, choose the product with the smallest product id.## sample
4
1 2 50
2 1 100
1 1 100
3 2 30
1