- محدودیت زمان: ۲ ثانیه
- محدودیت حافظه: ۲۵۶ مگابایت
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 rows and columns, containing blocks. The rows are numbered from to from north to south and the columns are numbered from to from west to east. The -th block on -th row is worth . Before the first row, between every two consecutive rows, and after the last row, there is a west-east street. The west-east streets are numbered from to 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 north-south streets are numbered from to 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 street segments, numbered from to from west to east. Similarly, each north-south street contains street segments, numbered from to from north to south. Since Manhootan is an expensive city, passing through street segments costs money. Passing through the -th segment of the -th west-east street costs and passing through the -th segment of the -th north-south street costs .
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, . At first, Bob is at . He is planning to drive to only going east and south, then returning to 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 and (), the number of rows and columns, respectively. The next lines describe the value of blocks; each containing numbers, where the -th number of the -th line denotes (). The next lines describe the cost of west-east street segments. Each line contain numbers, where the j-th number of the -th line denotes (). Finally, the next lines describe the cost of north-south street segments. Each line contains numbers, where the -th number of the -th line denotes ().
خروجی
Print the profit of the most profitable plan. Note that the answer can be negative, zero, or positive.
مثال
ورودی نمونه ۱
خروجی نمونه ۱
ارسال پاسخ برای این سؤال