#abc224h. H - Security Camera 2

H - Security Camera 2

Score : 600600 points

问题描述

我们有一个具有LL个左侧顶点和RR个右侧顶点的二分图。
高桥将在这些顶点安装监控摄像头。
安装摄像头会产生以下成本:

  • 在左侧第 ii 个顶点(1iL1 \le i \le L)安装每个摄像头需花费 AiA_i 日元(日本货币);
  • 在右侧第 jj 个顶点(1jR1 \le j \le R)安装每个摄像头需花费 BjB_j 日元(日本货币)。

允许在同一顶点上安装多个摄像头。

求满足以下条件时,安装摄像头所需的最小金额。

  • 对于所有整数对 (i,j)(i, j),满足 1iL,1jR1 \le i \le L, 1 \le j \le R,在左侧第 ii 个顶点和右侧第 jj 个顶点总共安装了至少 Ci,jC_{i,j} 个摄像头。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have a bipartite graph with LL vertices to the left and RR vertices to the right.
Takahashi will install surveillance cameras in these vertices.
Installing cameras incurs the following cost.

  • AiA_i yen (the Japanese currency) for each camera installed in the ii-th (1iL)(1 \le i \le L) vertex to the left;
  • BjB_j yen (the Japanese currency) for each camera installed in the jj-th (1jR)(1 \le j \le R) vertex to the right.

It is allowed to install multiple cameras on the same vertex.

Find the minimum amount of money needed to install cameras to satisfy the following condition.

  • For every pair of integers (i,j)(i, j) such that 1iL,1jR1 \le i \le L, 1 \le j \le R, there is a total of Ci,jC_{i,j} or more cameras installed in the ii-th vertex to the left and jj-th vertex to the right.

Constraints

  • All values in input are integers.
  • 1L,R1001 \le L,R \le 100
  • 1Ai,Bi101 \le A_i,B_i \le 10
  • 0Ci,j1000 \le C_{i,j} \le 100

Input

Input is given from Standard Input in the following format:

LL RR

A1A_1 A2A_2 \dots ALA_L

B1B_1 B2B_2 \dots BRB_R

C1,1C_{1,1} C1,2C_{1,2} \dots C1,RC_{1,R}

C2,1C_{2,1} C2,2C_{2,2} \dots C2,RC_{2,R}

\vdots

CL,1C_{L,1} CL,2C_{L,2} \dots CL,RC_{L,R}

Output

Print the answer as an integer.

Sample Input 1

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

Sample Output 1

37

You can achieve the objective for 3737 yen as follows, which is the minimum amount required.

  • Install 22 cameras on the 11-st vertex in the left.
  • Install 33 cameras on the 22-nd vertex in the left.
  • Install 22 cameras on the 33-rd vertex in the left.
  • Install 11 camera on the 11-st vertex in the right.
  • Install 11 camera on the 33-rd vertex in the right.

Sample Input 2

1 1
10
10
0

Sample Output 2

0

No camera may be needed.

Sample Input 3

5 6
3 2 6 7 5
4 9 8 6 2 3
2 0 2 1 1 0
2 3 2 1 0 0
2 2 4 0 2 2
4 1 0 3 0 2
1 0 0 2 2 5

Sample Output 3

79

update @ 2024/3/10 09:52:35