#K35772. Distinct Price Changes for Top-K Products

    ID: 25606 Type: Default 1000ms 256MiB

Distinct Price Changes for Top-K Products

Distinct Price Changes for Top-K Products

You are given details of N products and Q price update events. Each product is associated with an initial price and a popularity score. Your task is to determine the total number of distinct price changes that occur for the top K most popular products.

For the purpose of this problem, the top K products are those which have the highest popularity scores. If a product in the top K receives multiple price updates (even if the new price is the same across multiple events), each unique new price is counted once.

The relationship can be mathematically described as follows:

$$\text{result} = \sum_{p \in T} \left| \{ price \mid price \text{ is updated for product } p \} \right| $$

where \( T \) is the set of top K most popular products.

inputFormat

The first line contains three integers N, Q, and K separated by spaces.

The next N lines each contain a product's details: a string name, an integer price, and an integer popularity, separated by spaces.

The following Q lines each describe a price change event with a product's name (string) and its new price (integer), separated by spaces.

Example:

5 3 2
ProdA 100 250
ProdB 150 200
ProdC 100 300
ProdD 120 400
ProdE 90 100
ProdA 110
ProdD 115
ProdB 140

outputFormat

Output a single integer representing the total number of distinct price changes for the top K most popular products.

Example:

1
## sample
5 3 2
ProdA 100 250
ProdB 150 200
ProdC 100 300
ProdD 120 400
ProdE 90 100
ProdA 110
ProdD 115
ProdB 140
1

</p>