← Home
write a go solution for Description:
You are given a matrix a, consisting of n rows by m columns. Each element of the matrix is equal to 0 or 1.

You can perform the following operation any number of times (possibly zero): choose an element of the matrix and replace it with either 0 or 1.

You are also given two arrays A and B (of length n and m respectively). After you perform the operations, the matrix should satisfy the following conditions:

1. the number of ones in the i-th row of the matrix should be exactly A_i for every iin[1,n].
2. the number of ones in the j-th column of the matrix should be exactly B_j for every jin[1,m].

Calculate the minimum number of operations you have to perform.

Input Format:
The first line contains two integers n and m (2<=n,m<=50).

Then n lines follow. The i-th of them contains m integers a_i,1,a_i,2,...,a_i,m (0<=a_i,j<=1).

The next line contains n integers A_1,A_2,...,A_n (0<=A_i<=m).

The next line contains m integers B_1,B_2,...,B_m (0<=B_i<=n).

Output Format:
Print one integer — the minimum number of operations you have to perform, or -1 if it is impossible.

Note:
None. Output only the code with no comments, explanation, or additional text.