#P1361. Dual Field Crop Maximization

    ID: 14648 Type: Default 1000ms 256MiB

Dual Field Crop Maximization

Dual Field Crop Maximization

In this problem, you are given two fields, A and B, each with infinite capacity. You have n unique crop seeds, numbered from \(1\) to \(n\). For each crop \(i\), if planted in field A you gain a profit of \(a_i\), and if planted in field B you gain a profit of \(b_i\).

Furthermore, there are \(m\) special crop combinations. For the \(i\)-th combination, if all the crops in that combination are planted in field A, you obtain an extra profit of \(c_{1,i}\); otherwise, if they are all planted in field B, you obtain an extra profit of \(c_{2,i}\). (If the crops in a combination are split between the fields, no bonus is awarded for that combination.)

Your task is to decide which field to plant each crop in order to maximize the total profit. The total profit is the sum of the individual crop profits as well as any applicable bonus profits from the special combinations.

Input Format:

  • The first line contains two integers \(n\) and \(m\): the number of crops and the number of special combinations.
  • The second line contains \(n\) integers \(a_1, a_2, \dots, a_n\), where \(a_i\) represents the profit if crop \(i\) is planted in field A.
  • The third line contains \(n\) integers \(b_1, b_2, \dots, b_n\), where \(b_i\) represents the profit if crop \(i\) is planted in field B.
  • The next \(m\) lines describe the special combinations. Each of these lines starts with an integer \(k\), the number of crops in the combination, followed by \(k\) distinct integers identifying the crops (using 1-indexing), and then two integers \(c_1\) and \(c_2\) which are the bonus profits if the combination is planted entirely in fields A and B, respectively.

Output Format:

Output a single integer representing the maximum total profit achievable.

inputFormat

The input begins with two integers \(n\) and \(m\).
The second line contains \(n\) integers \(a_1, a_2, \dots, a_n\).
The third line contains \(n\) integers \(b_1, b_2, \dots, b_n\).
The next \(m\) lines each start with an integer \(k\), followed by \(k\) distinct integers representing the crop indices in the combination, and then two integers \(c_1\) and \(c_2\) for the bonus profit when planted entirely in fields A and B, respectively.

outputFormat

Output a single integer which denotes the maximum total profit that can be achieved by optimally assigning crops to the fields.

sample

3 1
1 2 3
3 2 1
2 1 3 10 5
16