Grocery Shopping
InterviewTime limit1sMemory limit128 MB
For each grocery item, find its matching store item by case-insensitive name and add the club-card saving on the units actually bought.
- Level
Easy3 of 10
- Topics
- Hash map, String, Simulation
- Solved
- No attempts yet
Problem
Vint Cerf and Bob Kahn, curious about the users of their network, decide to invite them all to a barbecue. Judging by the amount of traffic on the network, they are going to need a lot of food.
You are given the grocery store's inventory and their grocery list. The store's club card lets them buy some items at a cheaper price. Determine how much money they save in total by using the club card.
For each item on the grocery list, if the store carries it, they save (normal price - club price) on every unit they actually buy. The number of units bought is the smaller of the quantity desired and the quantity in stock . In other words, the amount saved on that item is . An item on the list that the store does not carry cannot be bought and contributes nothing. The total saving is the sum over all items.
Input
The first line contains the number of data sets. Then data sets follow, each in the form below.
The first line of each data set contains two integers and (), where is the number of different items in the store and is the number of different items on the grocery list.
Then lines follow, each describing one store item: an integer (the quantity currently in stock), then the normal price and the club card price , then a single space followed by the item name . Prices range from $0.00 to $99.99 and are always written with two decimal places (for example, $3.00). A name may contain upper- and lower-case letters and spaces.
Then lines follow, each describing one item on the list: an integer (the quantity desired), then a single space followed by the item name .
An item on the list is the same as a store item if their names are equal, ignoring case. The names in the input have no extra leading or trailing whitespace.
Output
For each data set, output Data Set x: on a line by itself, where is the data set's number. On the next line, output the exact amount saved by using the club card, written with a leading $ and two decimal places (no commas). Separate consecutive data sets with a blank line.