#K79572. Block Sum Grid Transformation
Block Sum Grid Transformation
Block Sum Grid Transformation
You are given a grid of integers with n rows and m columns, and an integer k. The grid is to be divided into blocks of size k \times k. For each block, compute the sum of all elements in that block. Note that if the grid dimensions are not exactly divisible by k, the blocks along the borders may be smaller than k \times k.
The number of blocks in the row dimension is \(\lceil \frac{n}{k} \rceil\) and in the column dimension is \(\lceil \frac{m}{k} \rceil\). Output the new grid of block sums, where each entry corresponds to the sum of the respective block in the original grid.
Input Format: The first line contains three integers n, m, and k. Each of the following n lines contains m integers representing the grid.
Output Format: Print the transformed grid. Each line should contain the block sums for that row, separated by spaces.
inputFormat
The first line of input contains three space-separated integers: n (the number of rows), m (the number of columns), and k (the block size).
This is followed by n lines, each containing m space-separated integers representing the grid elements.
outputFormat
Output the block sum grid. Each line corresponds to one row of the transformed grid, with values separated by a single space.
## sample4 4 2
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
14 22
46 54
</p>