Under construction

Still being built. Things may change

Cakes

Time limit2sMemory limit1024 MB

Summary
Choose which cakes to bake so that total cake price minus the cost of all needed ingredients and tools is as large as possible.
Level

Medium6 of 10

Topics
Graph, BFS
Solved
No attempts yet

Problem

The local cake shop is making a business plan for the next few months. The bakers have CC 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 GG, CC, and TT: the number of ingredients, recipes, and tool types. The second line contains CC integers c1,…,cCc_1, \ldots, c_C, the prices of the cakes. The third line contains GG integers g1,…,gGg_1, \ldots, g_G, the prices of the ingredients. The fourth line contains TT integers t1,…,tTt_1, \ldots, t_T, the prices of the tools.

The next CC lines each contain GG integers. The jj-th integer on line ii is ai,ja_{i,j}, the amount of ingredient jj in cake ii.

The last CC lines describe the tools. Line ii starts with nin_i, the number of tools cake ii requires, followed by nin_i distinct integers bi,kb_{i,k}, the tools needed to prepare cake ii.

Output

Print a single number: the maximum profit the cake shop can make.

Constraints

  • 1≤G,C,T≤2001 \leq G, C, T \leq 200
  • 0≤ci,ti≤1090 \leq c_i, t_i \leq 10^9
  • 0≤gj,ai,j≤1080 \leq g_j, a_{i,j} \leq 10^8
  • 0≤ni≤T0 \leq n_i \leq T
  • 1≤bi,k≤T1 \leq b_{i,k} \leq T

Hint

The maximum profit comes from baking cakes 1 and 2 but not cake 3.

Examples1

  1. Example 1

    Input
    5 3 4
    14 18 21
    1 2 3 1 2
    5 6 3 10
    0 0 1 2 0
    1 2 0 1 2
    5 2 1 0 0
    2 1 2
    2 2 3
    2 3 4
    
    Expected output
    3