#P9905. Sliding Frame Maximum

    ID: 23050 Type: Default 1000ms 256MiB

Sliding Frame Maximum

Sliding Frame Maximum

While wandering around Building \(21\), you came across a wall completely covered with numbers arranged in a table of \(n\) rows and \(m\) columns. Nearby, you found a frame that can exactly cover \(r\) rows and \(s\) columns of the wall. You also found a pencil and a piece of paper containing an empty table.

You decide to use the frame to fill in the paper. For every possible position where the frame can be placed (with its borders parallel to the wall and completely within the wall), you note the maximum number inside the frame and write that number in the corresponding cell of the paper table.

Formally, if the top-left corner of the frame is placed at the \(i\)-th row and \(j\)-th column of the wall (using 1-indexing), then the number written in the \((i, j)\) cell of the paper is the maximum value among all elements in the submatrix of size \(r \times s\) starting at \((i, j)\). Determine the complete table on the paper.

inputFormat

The input begins with a single line containing four space-separated integers \(n\), \(m\), \(r\), and \(s\), where \(n\) and \(m\) denote the dimensions of the wall's table, and \(r\) and \(s\) denote the dimensions of the frame.

This is followed by \(n\) lines, each containing \(m\) space-separated integers representing the table on the wall.

outputFormat

Output the table on the piece of paper. The table has \(n-r+1\) rows and \(m-s+1\) columns. Each number should be the maximum value found in the corresponding submatrix of the wall.

sample

3 3 2 2
1 2 3
4 5 6
7 8 9
5 6

8 9

</p>