Hide

Problem H
Packagemanager

Languages en sv

Doris has started her work as a packagemanager at the Pacman company (a part of the Sudo group). Her job is to make sure each of their stores has the most recent model of envelope, cardboard box, etc. Doris would however like to automate this task.

She has a list of all types of packages the company has, as well as the latest versions of these. For each store she also has a list of the packagetype they have in stock, and which versions they are. If any store has a type of package, but not the latest version, she has to alert them!

Input

Starts with a row of two integers, the number of packagetypes, $t$, and the number of stores, $b < 10^3$ ($t \cdot b < 10^6$). Next follows a row of $b$ integers $t_ i \leq t$, the number of packagetypes each store has. At last follows rows describing each package consisting of a name (consisting of a-z with length 3-10), a string, and a versionnumber, an integer $0 < v \leq 10^3$. The first $t$ such lines represents every package and their latest version, followed by $t_1, t_2, \dots $ rows representing the first, second $\dots $ store’s packagetypes and versionnumbers (guaranteed to be $\leq $ the latest version). Note that every package has a unique name and is mentioned at most once for each store.

Output

Print $b$ rows with one integer each, the number of versionsteps that has to be updated in total for each store.

Points

Your solution will be tested on a number of testgroups. To earn points in a testgroup all tests in it must succeed.

Group

Points

Limits

$1$

$20$

$t = 1$

$2$

$20$

$b = 1$

$3$

$20$

All stores has exactly one package with the wrong version

$4$

$20$

$t, b \leq 100$

$5$

$20$

No further restrictions

Sample Input 1 Sample Output 1
1 3
1 1 1
envelope 5
envelope 4
envelope 3
envelope 2
1
2
3
Sample Input 2 Sample Output 2
3 1
2
shopbag 5
backpack 5
paperbag 5
paperbag 5
backpack 2
3
Sample Input 3 Sample Output 3
2 4
1 2 1 2
easteregg 5
sock 12
easteregg 2
sock 11
easteregg 5
easteregg 1
easteregg 4
sock 12
3
1
4
1
Sample Input 4 Sample Output 4
3 2
1 2
largebox 13
smallbox 4
flatpack 5
smallbox 4
largebox 10
flatpack 4
0
4

Please log in to submit a solution to this problem

Log in