#P2488. [SDOI2011] 工作安排

[SDOI2011] 工作安排

Description

Your company has received a batch of orders. The orders require your company to provide nn types of products, numbered 1n1 \sim n, where CiC_i units of type ii are needed. The company has mm employees, numbered 1m1 \sim m. The types of products that employees can make differ. Each product must be made entirely by a single employee; it is not allowed to have one employee make some parts and then pass it to another employee to continue.

We use an m×nm \times n matrix AA consisting of 00 and 11 to describe which products each employee can make. The rows and columns of the matrix are numbered 1m1 \sim m and 1n1 \sim n, respectively. Ai,jA_i,j being 11 means employee ii can make product jj, and 00 means employee ii cannot make product jj.

If the company assigns too much work to an employee, the employee will become unhappy. We use an anger value to describe an employee’s mood. A higher anger value means the employee is more unhappy, and a lower anger value means the employee is happier. There is a functional relationship between an employee’s anger value and the number of products assigned to them. Since employees have different endurance, these functions differ between employees.

For employee ii, the function between their anger value and the number of products has Si+1S_i+1 segments. When they make the 1Ti,11 \sim T_{i,1}-th products, each product increases their anger by Wi,1W_{i,1}. When they make the (Ti,1+1)Ti,2(T_{i,1}+1) \sim T_{i,2}-th products, each product increases their anger by Wi,2W_{i,2}, and so on. For convenience, let Ti,0=0,Ti,si+1=+T_{i,0}=0, T_{i,s_{i+1}}=+\infty. Then when they make the (Ti,j1+1)Ti,j(T_{i,j-1}+1) \sim T_{i,j}-th products, each product increases their anger by Wi,jW_{i,j}, 1jSi+11 \le j \le S_i+1.

Your task is to design an assignment plan for the products so that the order requirements are satisfied, and the sum of anger values of all employees is minimized. Since we do not want to use a Special Judge, and to give contestants more time for the other two problems, you only need to output the minimal sum of anger values.

Input Format

The first line contains two positive integers mm and nn, the number of employees and the number of product types.

The second line contains nn positive integers, where the ii-th integer is CiC_i.

Each of the next mm lines contains nn integers describing the matrix AA.

Then there are mm sections, where the ii-th section describes the functional relationship between employee ii’s anger value and the number of products. Each section consists of three lines: the first line is a non-negative integer SiS_i; the second line contains SiS_i positive integers, where the jj-th integer is Ti,jT_{i,j} (if Si=0S_i=0, this line does not appear, i.e., the section has only two lines); the third line contains Si+1S_i+1 positive integers, where the jj-th integer is Wi,jW_{i,j}.

Output Format

Output a single integer: the minimal possible sum of anger values.

2 3
2 2 2
1 1 0
0 0 1
1
2
1 10
1
2
1 6
24

Hint

Constraints

  • There are 30%30\% of the testdata with 1n,m301 \le n, m \le 30.
  • About 30%30\% of the testdata satisfy Si=0S_i = 0.
  • About 30%30\% of the testdata satisfy Si1S_i \le 1 (excluding the above Si=0S_i = 0 testdata).

For all testdata, 1m,n2501 \le m, n \le 250, 0Si50 \le S_i \le 5, 0Ai,j10 \le A_{i, j} \le 1, 0<Ti,j<Ti,j+10 < T_{i, j} < T_{i, j + 1}, 0<Wi,j<Wi,j+10 < W_{i, j} < W_{i, j + 1}. All numbers are at most 10510^5.

Translated by ChatGPT 5