Under construction

Still being built. Things may change

Air Old Zeeland

Interview

Time limit1sMemory limit128 MB

Summary
For each customer, sum the prices of requested products whose shipping delay fits the wait limit, flag customers who miss any product, and count them.
Level

Easy3 of 10

Topics
Implementation, Array, Hash map, Simulation
Solved
No attempts yet

Problem

Air Old Zeeland — known informally as Air OZ — has begun letting customers redeem their loyalty points for products. Because the idea is new, Air OZ is testing the market with a small, curated set of products. The suppliers, however, often struggle to keep up with demand, so Air OZ decided to record, for each product, both its listed price (in loyalty points) and the number of days a customer must wait for it to be shipped. This lets them gauge how many discontented customers they have.

Input

The input consists of several scenarios.

The first line of each scenario contains an integer NN (0<N≤500 < N \le 50), the number of products on offer. A scenario whose first line is 00 marks the end of the input and must not be processed.

The next NN lines each describe one product. A line contains the product name, the number of loyalty points needed to redeem it, and the number of days to wait for shipping, separated by single spaces. A product name is at most 20 characters long and contains no spaces. No product costs more than 1000 loyalty points, and no product is delayed by more than 100 days.

The product lines are followed by a line containing CC (0<C≤5000 < C \le 500), the number of customers in this scenario. Each customer is described by a line containing the customer number, the number of products they wish to buy PP, and the maximum number of days MM they are willing to wait (0<P≤N0 < P \le N, 0<M<1000 < M < 100), separated by single spaces. That line is followed by PP lines, each naming one product the customer wants to order.

Output

For each customer, print one line with the customer number and the total value of the products they successfully purchased, separated by a single space. A product is purchased only if its shipping delay is at most the customer's maximum wait MM days; otherwise it is not purchased and the customer becomes discontented. If the customer failed to obtain at least one product they wanted, append a single space followed by an asterisk (*). Do not print a trailing space when there is no asterisk.

After listing all customers of a scenario, print a final line consisting of the text Number of discontented customers is:, a single space, and the number of discontented customers in that scenario (that is, the number of asterisks printed).

Hint

In the example, both products customer 1001 wants can be shipped within their acceptable time frame, so both are purchased.

Customer 1860's requested product cannot be shipped in time, so nothing is bought and the customer is discontented.

Customer 1025 can receive one of their two products in time (the iPodNano, worth 255) but not the other (the perfume), so the total is 255 and an asterisk is printed.

This leaves 2 customers who could not complete their purchases.

Examples1

  1. Example 1

    Input
    3
    iPodNano 255 0
    DucksFeetPerfume 120 15
    SilverCharmPendant 180 3
    3
    1001 2 3
    iPodNano
    SilverCharmPendant
    1860 1 5
    DucksFeetPerfume
    1025 2 6
    iPodNano
    DucksFeetPerfume
    0
    
    Expected output
    1001 435
    1860 0 *
    1025 255 *
    Number of discontented customers is: 2