HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Linear Data Structures: Arrays > problem:


50933 - Sum of the Biggest Neighbors

Guest
• Review clarifications (3)

Section problems

• 51008 - Sum of Regional Maxes
• 50989 - Rectangles and Points
• 51020 - Number of nodes removed
• 50932 - Shifting rows and columns
• 51141 - Most valuable stock items
• 51014 - Nine Men's Morris game
• 51019 - Finding the hidden message
• 50497 - Falling Bricks - Revisited
• 50933 - Sum of the Biggest Nei...
• 51100 - Minimum time to exit building
• 50444 - n digit kth number divisible...
• 50865 - Apartment Building Adminis...
• 51089 - Multiply a row and add it to ...
• 50874 - Apartment Building Adminis...
• 50531 - File Decryption
• 51012 - Palindrome-k
• 50469 - Letter Grades

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