#P1070. [NOIP 2009 普及组] 道路游戏

[NOIP 2009 普及组] 道路游戏

Description

Xiaoxin is playing a simple computer game.

In the game, there is a circular road with nn robot factories. Between every pair of adjacent robot factories, there is a short segment of road. Starting from some factory, Xiaoxin numbers the nn robot factories in clockwise order as 1n1 \sim n. Since the road is circular, factory nn and factory 11 are connected by a segment of road. Xiaoxin also numbers the nn road segments as 1n1 \sim n, and stipulates that segment ii connects factory ii and factory i+1i+1 (1in11 \le i \le n-1), while segment nn connects factory nn and factory 11.

During the game, in each time unit, every road segment will spawn some coins, and the number of coins changes over time; that is, the number of coins on the same road segment may differ between time units. Xiaoxin needs a robot’s help to collect the coins on the road. A robot must be purchased at a robot factory using some coins. Once purchased, the robot will walk along the circular road clockwise, moving once per time unit: in each time unit it moves from its current factory to the next factory and collects all coins on the road segment it traverses for Xiaoxin. For example, if Xiaoxin buys a robot at factory ii (1in1 \le i \le n), then starting from factory ii, the robot walks clockwise. On its first move, it traverses segment ii, reaches factory i+1i+1 (if i=ni=n, it reaches factory 11), and collects all coins on segment ii.

At no time may there be 22 or more robots on the road simultaneously, and each robot can walk at most pp times. When buying a robot, Xiaoxin must also set its number of moves, which can be any integer from 11 to pp. After finishing its assigned number of moves, the robot disappears automatically, and Xiaoxin must immediately buy a new robot at any factory and set its number of moves.

Additional notes:

  1. Time starts when Xiaoxin buys a robot for the first time.
  2. Buying a robot and setting its number of moves are instantaneous and take no time.
  3. Buying a robot and a robot’s walking are independent processes. You cannot buy a robot while another robot is moving; a robot starts moving only after it has been bought and its number of moves has been set.
  4. The purchase cost at the same factory is always the same, but the costs at different factories may differ.
  5. All robot purchase costs are deducted from the coins collected at the end of the game. Therefore, during the game, Xiaoxin never fails to proceed due to insufficient coins. Because of this, the final collected coins may be negative.

You are given, for every road segment and every time unit, the number of coins that appear, as well as the purchase cost at each robot factory. Please tell Xiaoxin the maximum number of coins he can collect after mm time units, after subtracting all robot purchase costs.

Input Format

The first line contains 33 positive integers n,m,pn, m, p, as described above.

The next nn lines each contain mm positive integers separated by single spaces. The ii-th line describes the number of coins that appear on segment ii in each time unit (11 \le coin count 100\le 100). That is, the jj-th (1jm1 \le j \le m) number on the ii-th line is the number of coins that appear on segment ii in the jj-th time unit.

The last line contains nn integers separated by single spaces. The ii-th number is the number of coins required to buy a robot at factory ii (11 \le coin count 100\le 100).

Output Format

Output a single line with 11 integer: the maximum number of coins Xiaoxin can collect in mm time units after subtracting all robot purchase costs.

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

Hint

  • For 40%40\% of the testdata: 2n402 \le n \le 40, 1m401 \le m \le 40.
  • For 90%90\% of the testdata: 2n2002 \le n \le 200, 1m2001 \le m \le 200.
  • For 100%100\% of the testdata: 2n10002 \le n \le 1000, 1m10001 \le m \le 1000, 1pm1 \le p \le m.

NOIP 2009 Junior Problem 4.

Translated by ChatGPT 5