#t402. 科技庄园(manor)
科技庄园(manor)
Picking Peaches
Background
Special for beginners, ^_^
Problem Description
Life has planted a field with some peach trees in it.
Life says to PFT: "I'll give you a certain amount of time to pick peaches, and you must come back to me within the given time; otherwise all the peaches you picked will be mine to eat!"
PFT thinks for a moment and finally agrees.
Because PFT is not good at math, he doesn't know how to maximize the value obtained within the given time.
Because PFT is not a robot, his stamina is not unlimited. He doesn't want to pick so many peaches that his stamina drops to , only to give all the peaches to Life for nothing. Also, PFT can pick from only one peach tree at a time, and each peach tree can be picked times (the number of peaches picked each time from the same tree is the same). After each picking he must return to the starting point (PFT cannot carry much at once), which is Life's location .
The coordinates of the peach at the upper-left corner of the experimental field are .
PFT can move only one unit per second, and each unit of movement costs stamina (picking costs no time or stamina, and movement is restricted to up, down, left, and right).
Input Format
The first line has four numbers , denoting the length and width of the experimental field, the time Life gives PFT, and PFT's stamina.
This is followed by an -row, -column matrix of the peach field, denoting the number of peaches that can be picked from each tree each time.
This is followed by another -row, -column matrix, denoting the maximum number of times each tree can be picked.
Output Format
One number: the maximum number of peaches PFT can obtain.
Sample Input 1
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
Sample Output 1
10
Hint
He can pick once from and once from ; neither stamina nor time allows picking any more peaches.
Constraints
1s, 1024KiB for each test case.
For :
of the data is in ;
of the data is in ;
.
The result is guaranteed to fit within long long.