#K66097. Maximum Bees
Maximum Bees
Maximum Bees
Simon is a beekeeper managing a large rectangular beehive represented as a grid with \(N\) rows and \(M\) columns. Each cell of the grid initially contains a certain number of bees. Simon can move bees from any cell to any of its 8 neighboring cells (up, down, left, right, and the four diagonal directions) an arbitrary number of times, as long as the bees remain within the grid.
Because the bees can be relocated arbitrarily many times through adjacent moves, it is always possible to gather all bees into a single cell. Your task is to compute the maximum number of bees that can be accumulated in one cell after the optimal moves.
inputFormat
The input begins with an integer \(T\) representing the number of test cases. Each test case is described as follows:
- A line containing two space-separated integers \(N\) and \(M\), denoting the number of rows and columns of the grid, respectively.
- \(N\) subsequent lines, each containing \(M\) space-separated integers, where the \(j^{th}\) integer in the \(i^{th}\) line is the number of bees initially present in the cell at row \(i\) and column \(j\).
outputFormat
For each test case, output a single integer on a new line: the maximum number of bees that can be gathered in one cell.
## sample2
3 3
1 2 3
4 5 6
7 8 9
2 2
1 0
0 1
45
2
</p>