#P2654. 原核生物培养

原核生物培养

Description

Professor W is studying a kind of prokaryote whose growth is peculiar: it can grow only by devouring its conspecifics. When two such organisms meet, the heavier one eats the lighter one (if they have the same weight, it is decided by “RP”, i.e., luck). After eating, the survivor’s weight becomes the sum of the two weights, and the amount of enzyme consumed is approximately equal to the sum of their weights.

Professor W currently has nn prokaryotes. Each time, he takes the mm lightest organisms from the petri dish for an experiment and lets them fight each other.

The operation is as follows: he places these mm organisms around a circular tube in some order according to their weights, then repeatedly chooses a pair of adjacent organisms and supplies enzyme to them; after they merge, the survivor’s weight becomes the sum of the two, and the enzyme consumed equals that sum. Repeat this until only one organism remains. The remaining one is put back into the petri dish, and the next experiment begins. Professor W wants the total enzyme consumption to be minimized after kk experiments. The input guarantees that there will never be a shortage of organisms.

Input Format

The first line contains three integers nn, mm, kk.

The second line contains nn integers, the initial weights of the nn organisms.

The next kk lines each contain mm integers. In the (i+2)(i+2)-th line, the jj-th number denotes the position where the jj-th lightest organism in the ii-th experiment is placed. For example, if m=5m=5 and the line is 1423514235, it means the smallest organism is placed in position 1, the second smallest in position 4, the third smallest in position 2, the fourth smallest in position 3, and the largest in position 5 (which is adjacent to position 1).

Output Format

Output a single integer, the minimal total amount of enzyme consumed after kk experiments.

10 2 3
1 2 3 4 5 6 7 8 9 10
1 2
1 2
1 2
18

Hint

Constraints: For 100%100\% of the testdata, 1<n10001 < n \leq 1000, 1m101 \leq m \leq 10, 1k1001 \leq k \leq 100. It is guaranteed that the result does not exceed 2312^{31}.

Sample explanation: In the first experiment, use weights 1,21, 2, consuming 33 enzyme and merging into weight 33. In the second experiment, use weights 3,33, 3, consuming 66 enzyme and merging into weight 66. In the third experiment, use weights 4,54, 5, consuming 99 enzyme and merging into weight 99. Therefore, the total enzyme consumption is 1818.

Translated by ChatGPT 5