HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Functions > problem:


50933 - Sum of the Biggest Neighbors

Guest
• Review clarifications (3)

Volume problems

• 50838 - Balanced Numbers
• 50724 - Number of Circles
• 50916 - Ascending Numbers
• 50926 - School Mail Merge
• 50917 - Descending Numbers
• 50982 - A thief in labyrinth
• 50980 - The smallest rectangle
• 50932 - Shifting rows and columns
• 50933 - Sum of the Biggest Nei...
• 50834 - The train which leaves the f...
• 51003 - Double Prime
• 50435 - City Electric Bills
• 50527 - Sum of LCMs
• 50353 - Cube of the Largest number
• 50539 - Number of Chairs - 2
• 50469 - Letter Grades
• 51012 - Palindrome-k

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.

Sum of the Biggest Neighbors

Math teacher of your brother gave a homework to learn and to follow directions. You want to write a program to assist your brother. The professor gives a 2D array, and then, he also gives some directions to move around the table. Your brother has to find the biggest of 4 neighbors for every stopping point and output sum of the biggest neighbors. If any neighbor is not in border, it's not calculated. If any stopping point is out of border (out of the limits of 2D array) he shows the current sum until that point.

Question: Write a program that reads a 2D array and k instructions. The program starts always upper left corner (1,1) and should output sum of the biggest neighbors.

Input specification
You will be given two integers in the beginning: the number of rows and columns. Then, you will be given a 2D array. The next line contains an integer (k) the number of instructions. The following k lines will have two information:

  • a char that shows the direction: U (Up), D (Down), R (Right), or L (Left)
  • a number showing the number of moves from the current position on the given direction.
where 0 ≤ rows and columns ≤ 100 and 0 ≤ k ≤ 2,000.

Output specification:
Show one integer.

Sample Input I
5 4
9 8 8 1
4 2 4 2
2 10 9 9
1 6 4 2
5 10 6 4
5
D 3
R 3
U 3
R 4
L 2
Sample Output I
23

Explanation: It starts from (1,1) and moves Down 3 (1,4). The numbers around are 5, 6 and 2. And thus, the biggest neighbor is 6. Then, he moves 3 cells to the right (4,4). The biggest number among the neighbors is 9. Then it moves 3 cells up. and the biggest among the neighbors is 8. He reaches out of borders after moving 4 cells right. So, the operation ends. And as a result, sum of the biggest neighbors is 23 (6 + 9 + 8).



Для отправки решений необходимо выполнить вход.

www.contester.ru