Naruto and Boruto

All submissions for this problem are available.
Naruto and Boruto both are capable of generating powerful shadow clones. One day they decided to test the strength of each others shadow clones. Naruto created N shadow clones indexed from 1 to N and Boruto created M shadow clones indexed from 1 to M. Naruto's clones are attacking Boruto's clones. Whenever Naruto's Clone attack it costs Naruto some energy. Similarly whenever Boruto's clone gets attacked it costs Naruto some energy. Initially Boruto's clones have some energy. Whenever a clone of Boruto gets attacked it loses 1 unit of enrgy.
You are given an array X of length M (X_{1}, X_{2}, ...., X_{M}) where X_{i} denotes the amount of energy i^{th} clone of Boruto initially has. For each of the clones of Naruto you are given a list of clones of Boruto that it can attack. You are also given an array Y of length N (Y_{1} , Y_{2} , ..., Y_{N}) and an array Z of length M (Z_{1}, Z_{2}, ..., Z_{M}). Whenever the i^{th} Clone of Naruto attacks it costs Y_{i} energy to Naruto and when the j^{th} clone of Boruto is attacked it costs Naruto Z_{j} amount of energy. Whenever a clone of Boruto gets attacked by Naruto it loses 1 unit of energy. Naruto's objective is to minimize Boruto's energy as much as possible. You need to find the minimum energy which Naruto will spend to achieve his objective.
Input
The first line of input contains two spaceseparated integers N and M denoting the number of shadown clones of Naruto and Boruto respectively.
The second line contains N space separated integers, the i^{th} integer of which denotes the array element Y_{i}.
Each of the next M lines contain two spaceseparated integers, where the i^{th} line contains the array elements X_{i} and Z_{i}.
Each of the next N lines contains the data regarding which clones of Boruto any clone of Naruto can attack as follows :
The i^{th} contains L_{i} denoting the number of clones of Boruto i^{th} clone of Naruto can attack followed by L_{i} spaceseparated integers denoting the indices of Boruto's clones that the i^{th} clone of Naruto can attack.
Output
The output should consist of a single integer denoting the minimum amount of energy which Naruto needs to spend to achieve his objective.
Constraints
 1 ≤ N ≤ 200
 1 ≤ M ≤ 200
 0 ≤ ∑ L_{i} ≤ 500
 0 ≤ X_{i}, Y_{i}, Z_{i} ≤ 10^{5}
Example
Input:
5 3
1 5 9 2 3
3 7
4 5
3 6
2 1 2
1 3
1 3
2 1 2
3 1 2 3 Output: 75
Author:  mohitbindal644 
Tags  mohitbindal644 
Date Added:  17022018 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, CLOJ, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions