#Lutece2174. 挖矿攻略

挖矿攻略

Migrated from Lutece 2174 挖矿攻略

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

在一个n*m的矩阵上,每个格子上有着两种矿【红矿】和【黑矿】。zh在最北边建造了【黑矿】的收集站,在最西边建造了【红矿】的收集站。现在,你需要在每个格子上铺上向北或向西的传送带,使得zh收集到的红、黑矿总和最多。

Input

第一行有2个整数n,m(1≤n≤500,1≤m≤500),含义如题目所示。

接下来n行m列为每个格子中【红矿】的数量。

再接下来n行m列为每个格子中【黑矿】的数量。

每个格子中【红矿】或【黑矿】数量小于1000。

Output

输出一个整数表示zh所能收集到的最多的矿数量。

Samples

4 4

0 0 10 9 

1 3 10 0

4 2 1 3 

1 1 20 0 

10 0 0 0 

1 1 1 30 

0 0 5 5 

5 10 10 10
98

Constraints

1≤n≤500,1≤m≤500

Note

每条传送带最终连向某个收集站,那个位置上对应颜色的矿才能被收集

Resources

2019 UESTC ACM Training for Dynamic Programming