#arc176e. E - Max Vector

E - Max Vector

Score: 800800 points

问题陈述

给定两个长度为NN的正整数序列:X=(X1,X2,,XN)X=(X_1,X_2,\dots,X_N)Y=(Y1,Y2,,YN)Y=(Y_1,Y_2,\dots,Y_N)

此外,还给出了MM个长度为NN的正整数序列。第ii个序列是 Ai=(Ai,1,Ai,2,,Ai,N)A_i = (A_{i,1},A_{i,2},\dots,A_{i,N})

对于每个i=1,2,,Mi = 1,2,\dots,M,你必须执行以下操作之一。你可以独立选择为每个ii执行哪个操作。

  • 将所有满足1jN1 \le j \le N的整数jjXjX_j替换为 max(Xj,Ai,j)\max(X_j,A_{i,j})
  • 将所有满足1jN1 \le j \le N的整数jjYjY_j替换为 max(Yj,Ai,j)\max(Y_j,A_{i,j})

在所有操作完成后,找出 j=1N(Xj+Yj)\sum_{j=1}^{N} (X_j + Y_j) 的可能最小值。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given two length-NN sequences of positive integers: X=(X1,X2,,XN)X=(X_1,X_2,\dots,X_N) and Y=(Y1,Y2,,YN)Y=(Y_1,Y_2,\dots,Y_N).

Additionally, you are given MM length-NN sequences of positive integers. The ii-th sequence is Ai=(Ai,1,Ai,2,,Ai,N)A_i = (A_{i,1},A_{i,2},\dots,A_{i,N}).

For each i=1,2,,Mi = 1,2,\dots,M, you must perform one of the following operations. You can independently choose which operation to perform for each ii.

  • Replace XjX_j with max(Xj,Ai,j)\max(X_j,A_{i,j}) for all integers jj such that 1jN1 \le j \le N.
  • Replace YjY_j with max(Yj,Ai,j)\max(Y_j,A_{i,j}) for all integers jj such that 1jN1 \le j \le N.

Find the minimum possible value of j=1N(Xj+Yj)\sum_{j=1}^{N} (X_j + Y_j) after all operations.

Constraints

  • 1N101 \le N \le 10
  • 1M5001 \le M \le 500
  • 1Xj,Yj,Ai,j5001 \le X_j, Y_j, A_{i,j} \le 500

Input

The input is given from Standard Input in the following format:

NN MM

X1X_1 X2X_2 \dots XNX_N

Y1Y_1 Y2Y_2 \dots YNY_N

A1,1A_{1,1} A1,2A_{1,2} \dots A1,NA_{1,N}

A2,1A_{2,1} A2,2A_{2,2} \dots A2,NA_{2,N}

\vdots

AM,1A_{M,1} AM,2A_{M,2} \dots AM,NA_{M,N}

Output

Print the answer.

Sample Input 1

3 2
4 4 2
3 1 5
2 5 2
1 2 4

Sample Output 1

21

One optimal sequence of operations is as follows:

  • Replace XjX_j with max(Xj,A1,j)\max(X_j,A_{1,j}), making X=(4,5,2)X = (4,5,2).
  • Replace YjY_j with max(Yj,A2,j)\max(Y_j,A_{2,j}), making Y=(3,2,5)Y = (3,2,5).

This sequence of operations achieves j=1N(Xj+Yj)=21\sum_{j=1}^{N} (X_j + Y_j) = 21.

Sample Input 2

3 5
4 13 10
14 9 4
4 6 4
13 18 16
8 13 5
7 18 17
20 20 14

Sample Output 2

84

Sample Input 3

5 12
330 68 248 387 491
295 366 376 262 192
280 121 17 168 455
288 179 210 378 490
150 275 165 264 287
66 331 207 282 367
303 215 456 214 18
227 326 103 443 427
395 57 107 350 227
318 231 146 2 116
57 325 124 383 260
147 319 23 177 445
254 198 32 85 56
68 177 356 41 471

Sample Output 3

3595