#abc326g. G - Unlock Achievement

G - Unlock Achievement

Score : 625625 points

问题描述

NN 项技能,编号为 11NN,以及 MM 项成就,编号为 11MM

每项技能都有一个正整数等级,且所有技能的初始等级均为 11

你可以支付 CiC_i 日元的成本来提升第 ii 项技能的等级 11 级。你可以根据需要重复此操作任意多次。

当你满足以下条件时,可以获得第 ii 项成就,并得到 AiA_i 日元的奖励:

  • 条件:技能 jj 的等级至少为 Li,jL_{i,j},对于所有的 j=1,,Nj=1,\ldots,N

请找出通过合理选择提升技能等级的方式所能获得的最大可能总奖励减去所需总成本。

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

Problem Statement

There are NN skills numbered 11 to NN and MM achievements numbered 11 to MM.

Each skill has a positive integer level, and the initial level of every skill is 11.

You can pay a cost of CiC_i yen to increase the level of skill ii by 11. You can do this as many times as you want.

Achievement ii is achieved when the following condition is satisfied for every j=1,,Nj=1,\ldots,N, for which you will receive a reward of AiA_i yen.

  • Condition: The level of skill jj is at least Li,jL_{i,j}.

Find the maximum possible total reward obtained minus the total cost required when appropriately choosing how to raise the skill levels.

Constraints

  • 1N,M501 \leq N,M \leq 50
  • 1Li,j51 \leq L_{i,j} \leq 5
  • 1Ai,Ci1061 \leq A_i,C_i \leq 10^6
  • All input values are integers.

Input

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

NN MM

C1C_1 \ldots CNC_N

A1A_1 \ldots AMA_M

L1,1L_{1,1} \ldots L1,NL_{1,N}

\vdots

LM,1L_{M,1} \ldots LM,NL_{M,N}

Output

Print the answer as an integer.

Sample Input 1

2 2
10 20
100 50
3 1
1 4

Sample Output 1

80

There are two skills. It costs 1010 yen to raise the level of skill 11 and 2020 yen to raise the level of skill 22.
There are two achievements. Achievement 11 is achieved when skill 11 is at least level 33 and skill 22 is at least level 11, for which you will receive 100100 yen. Achievement 22 is achieved when skill 11 is at least 11 and skill 22 is at least level 44, for which you will receive 5050 yen.

By raising skill 11 to level 33 and skill 22 to level 11, you will receive the reward of 100100 yen for the cost of 2020 yen, and the balance is 8080 yen.

Sample Input 2

2 2
10 20
100 50
3 2
1 4

Sample Output 2

70

By raising skill 11 to level 33 and skill 22 to level 44, you will receive the reward of 150150 yen for the cost of 8080 yen, and the balance is 7070 yen.

Sample Input 3

10 10
10922 23173 32300 22555 29525 16786 3135 17046 11245 20310
177874 168698 202247 31339 10336 14825 56835 6497 12440 110702
2 1 4 1 3 4 4 5 1 4
2 3 4 4 5 3 5 5 2 3
2 3 5 1 4 2 2 2 2 5
3 5 5 3 5 2 2 1 5 4
3 1 1 4 4 1 1 5 3 1
1 2 3 2 4 2 4 3 3 1
4 4 4 2 5 1 4 2 2 2
5 3 1 2 3 4 2 5 2 2
5 4 3 4 3 1 5 1 5 4
2 3 2 5 2 3 1 2 2 4

Sample Output 3

66900

update @ 2024/3/10 01:50:22