[Description]
John is playing a simple computer game.
There is a circular road in the game. There are n robot factories on the road, and two adjacent robot factories are connected by a short road. Starting from a robot factory, Xiao Xin sequentially numbered the N robot factories as 1 ~ N, because the road is circular, the N robot factory and the 1st robot factory are connected by a section of the road. John will connect the N roads in the robot factory to 1 ~ N, and specify section I to connect the I Robot Factory and I + 1 Robot Factory (1 ≤ I ≤ N-1 ), section N connects n robot factories and 1st robot factories.
During the game, there will be some gold coins on each section of the road within each unit time, and the number of gold coins will change over time, that is, the number of gold coins displayed on the same section of the road may be different in different units of time. Xiaoxin needs help from robots to collect gold coins on the road. The required robots must be purchased with some gold coins in the robot factory. Once purchased, the robots will walk clockwise along the ring road and every unit time, that is, from the current robot factory to the next adjacent Robot Factory, and collect all the gold coins on the road to xiaoxin, for example, xiaoxin in I (1 ≤ I ≤ n) robot No. Purchased a robot which will walk clockwise on the road starting from robot I. The first walk will go through the road No. I, arrive at the I + 1 Robot Factory (if I = N, the robot will arrive at 1st robot factories) and collect all the gold coins on the trojan road to Xiaomi. In the game, there cannot be two or more robots on the ring road at the same time, and each robot can walk a maximum of P times on the ring road. When purchasing a robot, Xiao Xin needs to set the walking count for the robot. The walking count can be 1 ~ Any integer between P. After a specified number of robots walk on the road, the robot automatically disappears. Xiaomi must buy a new robot in any robot factory immediately, set a new number of walking times for the new robot.
The following are some additional game descriptions:
- The game starts timing when it first buys robots from an early age.
- Buying robots and setting the number of robots to walk can be completed instantly without time required.
- Buying robots and walking robots are two independent processes. when walking a robot, you cannot buy a robot. After buying a robot and setting the number of walking robots, the robot can walk.
- The cost of buying robots in the same robot factory is the same, but the cost of buying robots in different robot factories is not necessarily the same.
- The gold coins paid by robots are deducted from the newly collected gold coins at the end of the game. Therefore, during the game process, you do not have to worry about the failure of buying robots due to insufficient gold coins. Because of this, the number of gold coins collected after the game ends may be negative.
We now know the number of gold coins per unit time on each section of the road and the costs required to purchase robots in each robot factory. Please tell xiaoxin that after m units of time, the maximum amount of gold coins that can be collected by a small new user is deducted from the cost of buying robots.
[Input format]
The three positive integers, n, m, and P in the first row indicate the meanings of the values as described in the topic.
In the next n rows, each row has M positive integers separated by a space, line I describes the number of gold coins (1 ≤ the number of gold coins ≤ 100) per unit time on Ma road I, that is, row I j (1 ≤ j ≤ m) the number indicates the number of gold coins on the Trojan horse in unit time J.
The last line contains N integers separated by a space, the I number indicates the amount of gold coins required to purchase robots at the I Robot Factory (1 ≤ the number of gold coins ≤ 100 ).
[Output format]
Contains an integer indicating the maximum amount of gold coins that can be collected by the robot within m units.
[Example input]
2 3 2
1 2 3
2 3 4
1 2
[Sample output]
5
[Analysis]
Step [I] [J] indicates the I time, and the number of steps used in the optimal condition to reach J.
F [I] [J] indicates the maximum amount of money that J can possess when I reaches the optimal method.
Past_max indicates the largest f [...] [J] in the previous moment.
Now_max indicates the current moment's largest f [...] [J].
# Include <stdio. h> # define maxn 1010int f [maxn] [maxn], step [maxn] [maxn], past [maxn], cost [maxn], W [maxn] [maxn]; int N, M, P, past_max, now_max; int main () {freopen ("game. in "," r ", stdin); freopen (" game. out "," W ", stdout); scanf (" % d ", & N, & M, & P); For (INT I = 1; I <= N; ++ I) for (Int J = 1; j <= m; ++ J) scanf ("% d ", & W [J] [I]); For (INT I = 1; I <= N; ++ I) scanf ("% d", & cost [I]); for (INT I = 2; I <= N; ++ I) past [I] = I-1; past [1] = N; For (INT I = 1; I <= N; ++ I) {step [1] [I] = 1; f [1] [I] = W [1] [past [I]-cost [past [I]; If (F [1] [I]> past_max) past_max = f [1] [I];} For (INT I = 2; I <= m; ++ I) {now_max =-1; for (Int J = 1; j <= N; ++ J) {If (step [I-1] [past [J] <p) if (past_max-cost [past [J]> F [I-1] [past [J]) {step [I] [J] = 1; f [I] [J] = past_max-cost [past [J] + W [I] [past [J];} else {step [I] [J] = step [I-1] [past [J] + 1; f [I] [J] = f [I-1] [past [J] + W [I] [past [J];} else {step [I] [J] = 1; f [I] [J] = past_max-cost [past [J] + W [I] [past [J];} if (F [I] [J]> now_max) now_max = f [I] [J];} past_max = now_max;} printf ("% d \ n", now_max ); return 0 ;}