Laundry
InterviewTime limit1sMemory limit1024 MB
Given colors partitioned into washable groups and counts of clothes per color, find how many machine loads of capacity M are needed.
- Level
Easy3 of 10
- Topics
- Math, Implementation, Greedy, Array
- Solved
- No attempts yet
Problem
Tomas does not like doing laundry, even though he owns a washing machine. Sometimes, when Tomas decides to wash his clothes, he has so many that they do not all fit in the machine at once, and he has to run the machine several times in a row.
Tomas also knows that only clothes of certain colors may be washed together. We say that colors which may be washed together belong to the same clothing group. Every color belongs to exactly one clothing group.
The washing machine can hold at most items of clothing at a time. Given which colors of clothing may be washed together, help Tomas count how many washes he must run to clean all of his clothes.
Input
The first line contains three integers , , and : the number of clothing colors, the number of distinct clothing groups, and the capacity of the washing machine.
Each of the next lines contains an integer followed by integers. is the number of clothing colors in the -th group, and the following integers are the colors that belong to that group.
The next line contains integers , where is the number of clothes of color that Tomas owns.
Clothing colors are denoted by the integers from to .
Output
Output a single integer — the number of washes Tomas must run.