#C9648. Top Performing Product
Top Performing Product
Top Performing Product
Problem Statement:
You are given a list of products with their initial scores. You will be asked to process a sequence of queries. There are two types of queries:
1. Update Query: In the format “1 i r” where you add an integer rating (r) to the (i)th product.
2. Query: In the format “2” which asks you to output the product with the highest score. In case of a tie, you must output the product with the smallest index.
The problem can be mathematically formulated as follows: Let (S = [s_1, s_2, \ldots, s_N]) be the scores of (N) products. For a query of type 2, output the smallest index (i) such that (s_i = \max_{1 \leq j \leq N} s_j).
Your task is to process the queries and output the answer for each type 2 query.
inputFormat
Input Format:
The first line contains an integer (N) representing the number of products.
The second line contains (N) space-separated integers representing the initial scores (s_1, s_2, \ldots, s_N).
The third line contains an integer (Q) representing the number of queries.
The following (Q) lines each contain a query. A query is either in the format "1 i r" to update the (i)th product by adding a rating (r), or "2" to output the product with the highest score.
outputFormat
Output Format:
For each query of type 2, print a single line containing the 1-based index of the product with the highest score. In the event of a tie, print the smallest index.## sample
5
10 20 30 40 50
7
1 3 10
1 5 20
2
1 1 5
2
1 5 5
2
5
5
5
</p>