Cakes
Time limit2sMemory limit1024 MB
Choose which cakes to bake so that total cake price minus the cost of all needed ingredients and tools is as large as possible.
Problem
The local cake shop is making a business plan for the next few months. The bakers have different recipes, each requiring its own set of ingredients and tools. Ingredients are consumed during baking, but tools are not, so a tool can be reused for other recipes. Right now the bakery has no ingredients or tools. The floods destroyed them, or the tax bureau took them away.
The son of the head chef convinced everyone to bake each type of cake only once. Internet users are reportedly willing to pay extra to be the sole owners of their own unique Nutty-Fudge Tart (NFT). The son has already estimated how much money each type of cake can earn. The bakers are now looking at each other, trying to decide which cakes to prepare for maximum profit. Given the costs of all ingredients and tools and the prices of the cakes, find the maximum profit the bakers can make.
Input
The first line contains three integers , , and : the number of ingredients, recipes, and tool types. The second line contains integers , the prices of the cakes. The third line contains integers , the prices of the ingredients. The fourth line contains integers , the prices of the tools.
The next lines each contain integers. The -th integer on line is , the amount of ingredient in cake .
The last lines describe the tools. Line starts with , the number of tools cake requires, followed by distinct integers , the tools needed to prepare cake .
Output
Print a single number: the maximum profit the cake shop can make.
Constraints
Hint
The maximum profit comes from baking cakes 1 and 2 but not cake 3.