#P2760. 科技庄园

科技庄园

Description

Life planted a field with some peach trees.

Life said to PFT: "I will give you a certain amount of time to pick peaches. You must return to me within the time limit, otherwise all the peaches you picked will be mine to eat!"

PFT thought for a while and agreed.

Because PFT is not good at math, he does not know how to obtain the maximum total within the time limit.

PFT is not a robot, so his stamina is limited. He does not want to pick so many peaches that his stamina becomes 00 and end up giving the peaches to Life for nothing. At the same time:

  • In each trip PFT can pick from exactly one peach tree.
  • Each tree can be picked at most KK times, and each pick from the same tree yields the same number of peaches.
  • After each pick he must return to the starting point, i.e., Life's location (0,0)(0, 0) (the coordinate of the top-left peach in the field is (1,1)(1, 1)).

Movement rules:

  • PFT can only move up, down, left, and right.
  • He moves 11 unit per second.
  • Moving 11 unit costs 11 stamina.
  • Picking costs no time and no stamina.

Input Format

The first line contains four integers NN, MM, TITI, AA, representing the length and width of the field, the time given by Life, and PFT's stamina.

Then an N×MN \times M matrix for the field, where each entry is the number of peaches obtained per pick from that tree.

Then another N×MN \times M matrix, where each entry is the maximum number of times KK that tree can be picked.

Output Format

One integer: the maximum number of peaches PFT can obtain.

4 4 13 20
10 0  0  0
0  0  10 0
0  0  10 0
0  0  0  0
1 0 0 0
0 0 2 0
0 0 4 0
0 0 0 0
10

Hint

Sample explanation:

You can pick 11 time at (1,1)(1, 1) and 11 time at (2,3)(2, 3). Time and stamina do not allow any more picking.

Constraints:

  • For 30%30\% of the testdata: 10N,M,TI5010 \le N, M, TI \le 50.
  • For 10%10\% of the testdata: 10N,M,TI10010 \le N, M, TI \le 100.
  • For KK: 10K10010 \le K \le 100. The result is guaranteed to fit in the range of long int.

Translated by ChatGPT 5