Restore the Array
InterviewTime limit2sMemory limit512 MB
Recover grid A from grid B, where B is built by overlapping A with A shifted down X and right Y so overlapping cells are summed.
- Level
Medium5 of 10
- Topics
- Matrix, Simulation, Implementation, Dynamic programming
- Solved
- No attempts yet
Problem
Given an array of size and two integers and , an array of size can be made by overlapping the array with the array shifted down by cells and right by cells. Where numbers overlap, they are added together.
That is, the value at of array is one of the following three.
- If lies in neither array, .
- If lies in both arrays, .
- If lies in exactly one of the arrays, or .
Given the array and the integers and , find the array .
Input
The first line contains four integers , , , . The next lines give the elements of array .
The input is always given such that array exists.
Output
Print the elements of array over lines.