A logistics company tracks crate specifications and how many of each crate type sit in every one of its freight yards. Each crate type has a fixed width, length, and height (its dimensions never change), while every yard independently records how many units of a crate type it currently holds. Given the catalog of crate dimensions and the list of (yard, crate type, unit count) storage records, compute for every yard mentioned in the records the total volume of everything stored there: the sum, over every record for that yard, of (units stored) x (crate's width x length x height). Report this total for each distinct yard, in ascending alphabetical order of the yard's name.
Line 1 contains a single integer n, the number of crate types.
Each of the next n lines contains four space-separated integers: a crate id pid (unique per crate type), and w, l, h -- the crate's width, length, and height.
The next line contains a single integer m, the number of storage records.
Each of the next m lines contains a yard name (a single token with no whitespace), followed by a crate id pid (guaranteed to appear in the catalog above) and an integer units, the number of that crate type currently stored in that yard.
Let k be the number of distinct yard names appearing in the storage records. Print k lines, sorted by yard name in ascending lexicographic order. Each line contains the yard name followed by a single space and the yard's total stored volume, computed as described above.
Example 1
Input
2 1 5 10 2 2 3 3 3 3 yardA 1 2 yardB 2 1 yardA 2 1
Expected
yardA 227 yardB 27
Explanation
Crate 1 has volume 5*10*2=100 and crate 2 has volume 3*3*3=27. yardA holds 2 units of crate 1 (200) plus 1 unit of crate 2 (27), for a total of 227. yardB holds only 1 unit of crate 2, so its total is 27. Sorted alphabetically, yardA is printed before yardB.
Example 2
Input
1 7 2 2 2 3 z1 7 5 a9 7 3 z1 7 1
Expected
a9 24 z1 48
Explanation
Crate 7 has volume 2*2*2=8. Yard z1 appears in two records (5 units and 1 unit of crate 7), for a combined total of 6*8=48. Yard a9 has 3 units of crate 7, for a total of 24. Sorted alphabetically, a9 (24) is printed before z1 (48).
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 →