| 
 
 
| Feedback |  | If you notice incorrect translations in Contester, please let author know. |  
 | Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb. Question by Ibrahim Mesecan.
 
 
 Snake  Your brother likes the snake game, but he is small 
and he cannot play the original game. You want to 
design a simplified version for him with the 
following rules: 
If the snake goes over bonuses, it’s rewarded 
lifepoints. If the snake goes over obstacles, 
it’s punished, lifepoint is decreased. After a 
cell visited, the bonus or the obstacle disappear 
from the cell (cell changes to 0). Game ends in 
three conditions:Board is square matrix (n x n)Snake starts the game from the upper left 
corner with an initial lifepoint (m). Initially, 
upper left corner always contains  zero.The size of the snake is fixed 1x1 and it 
doesn’t grow or shrinkOn random positions of the board, there are 
different objects
Bonus: positive integersObstacles: negative numbersEmpty tiles: where snake can move 
freely (zero)  
if the snake hits to a border or if its lifepoint is decreased to zero or less or when the actions given are completed  
Question:
Write a program that reads a two dimensional board 
information and k movement instructions. Then 
your program will calculate and show the number 
of moves that the snake completed and the lifepoints 
when program ended. 
 
Input specification  You will be given 3 integers in the first line:
 
where 1 ≤ n ≤ 25, 0 ≤ m ≤ 2000 
and 1 ≤ k ≤ 100. Then, in the following 
n lines, you will be given n integers where 
each number is between -100 and +100. Then in 
the following k lines, you will be given k 
instructions. Each instruction line will have a 
letter (U, D, R or L) and an integer.n: the size of board  m: initial points that the snake has k: the number of instructions given  
Letter: U: Up; D: Down; R: Right; or L: Left an integer:  the number of moves in the given direction  Output specification  Show two integers:
 
The number of moves that the snake completed Lifepoints when the game ended    
  
| Sample Input I 
 
5 10 5 0 4 0 0 -30
 0 10 0 -15 0
 -5 0 6 0 20
 12 0 -9 0 0
 0 0 -7 0 0
 R 2
 D 3
 R 1
 U 3
 L 3
 
 | Sample Output I 
 
8 -4 
 |    Explanation: 
The snake starts from the upper left 
corner with an initial lifepoint, 10. 
 
game ends because the lifepoints gets less than zero.It goes two right and collects 
4 points: 14 lifepointsThen it goes three down: collects 
6 points and punished 9 points: 11 lifepointsIt goes 1 right It goes 2 up: the lifepoint decreases to -4   
 Äëÿ îòïðàâêè ðåøåíèé íåîáõîäèìî âûïîëíèòü âõîä.
 
 
 |