Jumping King
Time limit2sMemory limit1024 MB
Given a grid of jump directions and distances, change at most K cells to find the minimum and maximum number of escapable cells.
Problem
Jumping King is a superhuman with enormous jumping power. One day, while traveling the world by jumping, he landed badly and got trapped in a jump prison. The jump prison is a grid with rows and columns, and from each cell you can only jump in the given direction and distance. If you can escape the prison by starting a jump from a certain cell, that cell is called an escapable cell. Escaping the prison means that the result of a jump lands outside the grid.

In the jump prison above, the cell at (2, 2) marked R2 is an escapable cell, and no other cell is escapable.
Input
The first line contains the grid size , and the number of cells that you can modify, separated by spaces.
The next lines each contain characters , separated by spaces, giving the jump direction of each cell. Each character is one of L, R, U, D.
The next lines each contain integers , separated by spaces, giving the jump distance of each cell.
Output
Print the minimum and the maximum number of escapable cells that can be achieved by modifying at most cells, separated by a space.