#K92537. Highest Population Density Finder
Highest Population Density Finder
Highest Population Density Finder
In this problem, you are given a grid of size (n \times m) where each cell represents the population density of that location. You are also provided with (q) queries. Each query defines a subarea of the grid by four integers (x_1, y_1, x_2, y_2) (0-indexed) representing the top-left and bottom-right corners of the subarea. Your task is to determine, for each query, all the cell coordinates within the subarea that have the highest population density.
Note that if multiple cells have the same maximum density, they should all be reported in the order they are visited (scanning row by row from (x_1) to (x_2) and, within each row, from (y_1) to (y_2)).
inputFormat
The first line of input contains three integers: (n), (m) and (q) — the number of rows, columns, and queries respectively.
This is followed by (n) lines, each containing (m) integers representing the grid's population densities.
Then, (q) lines follow, each containing four integers (x_1), (y_1), (x_2), (y_2) which define a subarea for the query.
outputFormat
For each query, output one line containing the result. The result should start with an integer (k) — the number of cells having the highest population density in that subarea, followed by (k) pairs of integers. Each pair represents the row and column of a cell. The order of the cell coordinates should follow the scanning order from top to bottom and left to right.## sample
3 3 1
10 20 30
25 35 15
5 40 10
1 1 1 1
1 1 1