#ARC067D. [ARC067F] Yakiniku Restaurants

[ARC067F] Yakiniku Restaurants

Score : 10001000 points

Problem Statement

There are NN barbecue restaurants along a street. The restaurants are numbered 11 through NN from west to east, and the distance between restaurant ii and restaurant i+1i+1 is AiA_i.

Joisino has MM tickets, numbered 11 through MM. Every barbecue restaurant offers barbecue meals in exchange for these tickets. Restaurant ii offers a meal of deliciousness Bi,jB_{i,j} in exchange for ticket jj. Each ticket can only be used once, but any number of tickets can be used at a restaurant.

Joisino wants to have MM barbecue meals by starting from a restaurant of her choice, then repeatedly traveling to another barbecue restaurant and using unused tickets at the restaurant at her current location. Her eventual happiness is calculated by the following formula: "(The total deliciousness of the meals eaten) - (The total distance traveled)". Find her maximum possible eventual happiness.

Constraints

  • All input values are integers.
  • 2N5×1032 \leq N \leq 5 \times 10^3
  • 1M2001 \leq M \leq 200
  • 1Ai1091 \leq A_i \leq 10^9
  • 1Bi,j1091 \leq B_{i,j} \leq 10^9

Input

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

NN MM

A1A_1 A2A_2 ...... AN1A_{N-1}

B1,1B_{1,1} B1,2B_{1,2} ...... B1,MB_{1,M}

B2,1B_{2,1} B2,2B_{2,2} ...... B2,MB_{2,M}

::

BN,1B_{N,1} BN,2B_{N,2} ...... BN,MB_{N,M}

Output

Print Joisino's maximum possible eventual happiness.

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

The eventual happiness can be maximized by the following strategy: start from restaurant 11 and use tickets 11 and 33, then move to restaurant 22 and use tickets 22 and 44.

5 3
1 2 3 4
10 1 1
1 1 1
1 10 1
1 1 1
1 1 10
20