Hardware Sales
InterviewTime limit1sMemory limit512 MB
Given three lists of (item ID, units) purchases, count items whose total units reach 20 or more in all three stores, printing IDs in first-appearance order.
- Level
Medium4 of 10
- Topics
- Hash map, Implementation, Array, Sorting
- Solved
- No attempts yet
Problem
Bree Kim Orter owns three hardware stores in different parts of the state. She wants to know which items are popular across the state, specifically those items that have sold 20 or more units in each of her stores. For each store she has a chronological list of purchases made during the past week. Each purchase record consists of two integers: the ID number of the item and the number of units purchased. An example of such a list is shown below:
178293 3 457839 10 322228 1 ...
This list indicates that the first purchase that week was three units of the item with ID #178293. The next purchase involved 10 units of item #457839, and so on. Given three of these lists (one from each store), Bree wants to determine the number of items which sold 20 or more units in each store during the week.
Input
Input starts with a line containing three integers n1 n2 n3, where 1 ≤ n1, n2, n3 ≤ 100 are the number of purchases in each of the three lists. Following this is the purchase list from the first store, which contains n1 pairs of positive integers, where the first number in each pair is a 6-digit ID number (possibly with leading zeros) and the second is the number of units sold. These n1 pairs may span multiple lines. After this, starting on a new line, is the purchase list of the second store, and following this, again starting on a new line, is the purchase list of the third store. All purchase amounts are ≤ 100. An ID number may show up multiple times on a list.
Output
Output the number of items that have sold at least 20 units in each of the three stores. After this number, output the ID numbers of the items. Print the ID numbers in the order that they first appear in the input file.