A night-market noodle stall keeps a running ledger of every customer it serves, in order. The stall owner runs a loyalty scheme: counting every customer ever served at the stall (starting from the very first), whenever the running count of customers reaches a multiple of n, that customer's entire basket total is discounted by a fixed percentage; every other customer pays the full price. Each item in the stall's catalogue has a fixed unit price, identified by an item id.
Given the catalogue, the loyalty interval n and the discount percentage, and the sequence of baskets (one per customer, in the order they were served), compute the final amount billed to each customer, in order.
Line 1: three integers n discount m — n is the loyalty interval, discount is the percentage discount (0–100) applied to the whole basket for every n-th customer, m is the number of distinct items in the catalogue.
Next m lines: two integers id price — one catalogue item's id and its unit price.
Next line: one integer q — the number of customers to process, in serving order.
Next q lines: each line describes one customer's basket, starting with an integer k (the number of (id, amount) entries in that basket), followed by k pairs of integers id amount, all on the same line. The same id may appear more than once within one basket. Every id referenced is guaranteed to appear in the catalogue.
Print q lines. The i-th line is the total amount billed to the i-th customer, formatted with exactly two digits after the decimal point.
1 <= n <= 10^40 <= discount <= 1001 <= m <= 2001 <= id <= 10^5, all catalogue ids distinct1 <= price <= 10^41 <= q <= 10001 <= k <= 501 <= amount <= 1000Example 1
Input
3 10 2 1 5 2 3 3 2 1 2 2 1 1 2 2 1 1 1
Expected
13.00 6.00 4.50
Explanation
n=3, discount=10%, catalogue: item 1 costs 5, item 2 costs 3. Customer 1 buys 2 of item 1 and 1 of item 2: 5*2 + 3*1 = 13; this is the 1st customer served, not a multiple of 3, so pays 13.00. Customer 2 buys 2 of item 2: 3*2 = 6; the 2nd customer served, not a multiple of 3, pays 6.00. Customer 3 buys 1 of item 1: 5; this is the 3rd customer served, a multiple of 3, so a 10% discount applies: 5 * 0.90 = 4.50.
Example 2
Input
1 50 1 7 100 2 1 7 1 1 7 1
Expected
50.00 50.00
Explanation
n=1 means every customer's running count is a multiple of 1, so every customer gets the 50% discount. Both customers buy one unit of item 7 (price 100), raw total 100 each, discounted to 100 * 0.50 = 50.00 each.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →