#K81042. Total Inventory Query
Total Inventory Query
Total Inventory Query
You are given a list of shipment records and a query. Each shipment record consists of a date, a product ID, and a quantity. The query contains a product ID and a date. Your task is to compute the total quantity of the specified product in the inventory up to and including the given date.
More formally, if you are given shipments as a 2D array where each element is [date, product_id, quantity] and a query [P, D], you need to compute the sum
\( \text{Total} = \sum_{\substack{(d, p, q) \in shipments \\ p = P \; \text{and} \; d \leq D}} q \)
If there are no shipments meeting the condition, the result is 0.
inputFormat
The input is read from standard input (STDIN) in the following format:
- The first line contains an integer
n
(the number of shipment records). - The next
n
lines each contain three space-separated integers:date
,product_id
, andquantity
. - The last line contains two space-separated integers representing the query: first the
product_id
to query, then thedate
.
Note: If n = 0
, there will be no shipment lines, but the query line will still be provided.
outputFormat
Output to standard output (STDOUT) a single integer: the total quantity of the specified product in the inventory at the given date.
## sample4
1 0 5
2 0 15
3 1 7
5 0 10
0 4
20