Skidor
Time limit7sMemory limit1024 MB
Find an L by L square with no trees whose height range is minimal, breaking ties by smallest top row then left column.
- Level
Hard8 of 10
- Topics
- Sliding window, Heap, Matrix, Implementation
- Solved
- No attempts yet
Problem
Johan likes to ski. Not slalom, which Johan is very afraid of. Cross-country skiing, on the other hand, is his thing. When you go cross-country skiing, however, you need large flat surfaces.
Johan has surveyed a large rectangular area out in the forest, whose ground is quite uneven. Here Johan wants to pick out a certain square to ski around on, one large enough to make the skiing interesting. The square must have exactly size , and have sides parallel to the sides of the area.
Now he asks you to find such a square. For it to suit cross-country skiing well, he has two requirements. First, there must be no trees in the square, and second, the height difference between the highest and lowest point in this square must be as small as possible.
If there are several such possible squares, you should first choose the one that lies farthest north, i.e. has the lowest row number. If there are still several possible, you should second choose the one that lies farthest west, i.e. has the lowest column number.
Input
The first line contains three integers , , such that . is the number of rows in the large area, the number of columns, and the size of the square to find.
Then follow lines, one for each row in the area. A line contains integers, one for each column in the area.
The th number on the th line describes the height at that point in the area, which is such that . If , there is instead a tree standing at that spot.
Output
Find , such that Johan's square spans the coordinates , . and must be 0-indexed, for example if the first row (the one farthest north) is meant, and if the first column (the one farthest west) is meant.
It is guaranteed that a solution exists.