COCI '23 Contest 1 #3 AN2DL
View as PDF
While wandering around Building 21, you came across a wall completely covered
with numbers, arranged in a table of  rows and 
 columns. Soon you noticed
that there was a frame leaning against the wall large enough to frame 
 rows and
 columns of the table on the wall. And next to the frame you found a pencil and
a piece of paper containing an empty table.
You are sad that the table on the piece of paper is empty, so you decided to play around with the frame to fill it.
You leaned the frame against the wall so that the number in the -th row and 
-th column is in the upper
left corner, and the borders of the frame are parallel to the edges of the wall. Considering the numbers
inside the frame, and since you like large numbers, you have decided to write the largest among them in
the 
-th row and 
-th column of the table on the piece of paper.
You repeated the process for every possible position of the frame on the wall (such that the frame is
entirely on the wall, and that there are exactly  numbers inside it), making sure that the edges of the
frame are parallel to the edges of the wall.
When you were done, the table on the piece of paper was even more beautiful than the one on the wall. What numbers are in the table on the piece of paper?
Input Specification
The first line contains two integers  and 
 
, the number of rows and columns of the
table on the wall.
Each of the following  lines contain 
 integers 
 
, where 
 is the number in the 
-th
row and 
-th column of the table on the wall.
The last line contains two integers  and 
 
, the size of the frame.
Output Specification
Output the numbers written in the table on the piece of paper.
Constraints
| Subtask | Points | Constraints | 
|---|---|---|
| 1 | 12 | |
| 2 | 17 | |
| 3 | 25 | |
| 4 | 56 | No additional constraints. | 
Sample Input 1
3 3
1 1 2
2 3 4
4 3 2
3 3
Sample Output 1
4
Explanation for Sample 1
The frame is big enough to fit the entire table on the wall. The largest number inside the frame is , so
that is the only number written on the table on the piece of paper.
Sample Input 2
3 3
1 1 2
2 3 4
4 3 2
2 1
Sample Output 2
2 3 4
4 3 4
All possible frame positions are shown in the picture below. The largest number for each of the positions is written in red.

Sample Input 3
5 5
-1 -3 -4 -2 4
-8 -7 -9 -10 11
5 2 -8 -2 1
13 -3 -2 -6 -9
11 6 2 7 4
2 3
Sample Output 3
-1 -2 11
5 2 11
13 2 1
13 7 7
                    
Comments