ساعت
۹۰۱۲۳۴۵۶۷۸۹۰۹۰۱۲۳۴۵۶۷۸۹۰
ساعت
دقیقه
۹۰۱۲۳۴۵۶۷۸۹۰۹۰۱۲۳۴۵۶۷۸۹۰
دقیقه
ثانیه
۹۰۱۲۳۴۵۶۷۸۹۰۹۰۱۲۳۴۵۶۷۸۹۰
ثانیه
  • محدودیت زمان: ۲ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

There are two types of angry people in this world, those who burn and those who rob. But we programmers know that there is a third type; those who counter their anger, by both burning and robbing.

توضیح تصویر

Bob lives in Manhootan. The city of Manhootan is like a grid of nn rows and mm columns, containing n×mn \times m blocks. The rows are numbered from 00 to n1n-1 from north to south and the columns are numbered from 00 to m1m-1 from west to east. The jj-th block on ii-th row is worth AijA_{ij} . Before the first row, between every two consecutive rows, and after the last row, there is a west-east street. The n+1n + 1 west-east streets are numbered from 00 to nn from north to south. Similarly, before the first column, between every two consecutive columns, and after the last column, there is a north-south street. The m+1m + 1 north-south streets are numbered from 00 to mm from west to east. The part of a street that is between two adjacent blocks is called a street segment. Each west-east street contains mm street segments, numbered from 00 to m1m - 1 from west to east. Similarly, each north-south street contains nn street segments, numbered from 00 to n1n - 1 from north to south. Since Manhootan is an expensive city, passing through street segments costs money. Passing through the jj-th segment of the ii-th west-east street costs HijH_{ij} and passing through the jj-th segment of the ii-th north-south street costs VijV_{ij}.

توضیح تصویر

After a recent crisis in Manhootan, Bob got angry. He pierced his car’s fuel tank to make it leak on the streets he passes. Let’s call the intersection of i-th west-east street and j-th north-south street, T(i,j)T(i, j). At first, Bob is at T(0,0)T(0, 0). He is planning to drive to T(n,m)T(n, m) only going east and south, then returning to T(0,0)T(0, 0) only going west and north. Then, he is going to light the leaked fuels and put the streets on fire. After that, Bob will rob all the blocks that are caught inside the fire, i.e., any block that can not reach outside of Manhootan without crossing a burning street, will be robbed by Bob. The figure shows one possible plan for Rob in the sample.

Now, you can’t be like Bob, but you can help him find the most profitable burn-and-rob plan. In other words, maximize the total value of the robbed blocks minus the total cost of the passed street segments. A street segment may be passed twice, which should be paid for each separately

ورودی

The first line of input contains two integers nn and mm (1n,m2001 \leq n, m \leq 200), the number of rows and columns, respectively. The next nn lines describe the value of blocks; each containing mm numbers, where the jj-th number of the ii-th line denotes AijA_{ij} (1Aij1001 \le A_{ij} \le 100). The next n+1n+1 lines describe the cost of west-east street segments. Each line contain mm numbers, where the j-th number of the ii-th line denotes HijH_{ij} (1Hij10001 \leq H_{ij} \leq 1000). Finally, the next m+1m + 1 lines describe the cost of north-south street segments. Each line contains nn numbers, where the jj-th number of the ii-th line denotes VijV_{ij} (1Vij10001 \leq V_{ij} \leq 1000).

خروجی

Print the profit of the most profitable plan. Note that the answer can be negative, zero, or positive.

مثال

ورودی نمونه ۱

2 3
6 7 3
12 10 7
4 13 5
2 5 5
12 12 6
3 7
6 4
6 2
9 4
Plain text

خروجی نمونه ۱

-28
Plain text

ارسال پاسخ برای این سؤال
فایلی انتخاب نشده است.