Description
Get out from the maze!
He looks around, finding that the maze has only one exit but it has been locked. He has not enough energy to break the door and he must move out to find extra bonuses of energy hidden in the maze. He can move toward 4 directions: left, right, up, and down, which will take 1 second in a single move.
Unfortunately, there is an evil machine which will detect whether he is still there or not every L seconds in the initial place where he is located. And if he is out of the maze, the machine will surely be out of service.
Right after he is in the exit grid, he will be considered to be outside the maze.
Input
The input consists of one or more test cases.
First line of each test case contains 5 integers W(1<=W<=50), H(1<=H<=50), L(1<=L<=1,000,000), M(1<=M<=10), and S(0<=S<=10,000,000), indicating:
W: the width of the maze.
H: the height of the maze.
L: time of the round of the machine.
M: the number of the bonuses of energy.
S: energy needed to break the lock.
The next line contains M integers indicating the list of the energy-bonus.
Then there comes the map of the maze:
#: wall
.: empty place
$: initial position
<: exit grid
@: energy bonuses
Energy bonuses are ordered from the top to bottom, left to the right.
First line of each test case contains 5 integers W(1<=W<=50), H(1<=H<=50), L(1<=L<=1,000,000), M(1<=M<=10), and S(0<=S<=10,000,000), indicating:
W: the width of the maze.
H: the height of the maze.
L: time of the round of the machine.
M: the number of the bonuses of energy.
S: energy needed to break the lock.
The next line contains M integers indicating the list of the energy-bonus.
Then there comes the map of the maze:
#: wall
.: empty place
$: initial position
<: exit grid
@: energy bonuses
Energy bonuses are ordered from the top to bottom, left to the right.
Output
For each test case, output “YES” or “NO”
Sample Input
3
4 4 2 2 200
100 200
####
#$@#
#@<#
####
4 4 1 2 300
100 200
####
#$@#
#@<#
####
12 5 13 2 400
100 200
############
#@.........#
#.########.#
#$...@....<#
############
4 4 2 2 200
100 200
####
#$@#
#@<#
####
4 4 1 2 300
100 200
####
#$@#
#@<#
####
12 5 13 2 400
100 200
############
#@.........#
#.########.#
#$...@....<#
############
Sample Output
YES
NO
NO
NO
NO
Hint
Source