P9905 [COCI 2023/2024 #1] AN2DL

Description

While wandering around Building $21$, you came across a wall completely covered with numbers, arranged in a table of $n$ rows and $m$ columns. Soon you noticed that there was a frame leaning against the wall large to frame $r$ rows and $s$ 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 $i$-th row and $j$-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 $i$-th row and $j$-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 $r \times s$ 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 Format

The first line contains two integers $n,m$ representing the height and width of the matrix. The next $n$ lines contain $m$ integers each, representing the matrix $A$. The last line contains two integers $r,s$.

Output Format

There are $n-r+1$ rows, each row has $m-s+1$ numbers, and the number in the $i$th row and $j$th column represents the maximum value of the $r\times s$ submatrix element with $(i,j)$ as the upper left corner, that is, $\max\limits_{i\leq x\leq i+r-1,j\leq y\leq j+s-1}A_{x,y}$.

Explanation/Hint

[COCI2023-2024](https://hsin.hr/coci/archive/2023_2024/) [CONTEST #1](https://hsin.hr/coci/archive/2023_2024/contest1_tasks.pdf) Problem 3. AN2DL