Matrix Summation

Company: Paytm_3oct

Difficulty: easy

Problem Statement

Matrix Summation A program converts a before matrix into an after matrix. For every cell (x, y) of the after matrix it runs the following algorithm: s = 0; for (i = 0; i <= x; i += 1) { for (j = 0; j <= y; j += 1) { s = s + before(i, j); } } after(x, y) = s; In words, after(x, y) is the sum of every value of before in the rectangle whose corners are (0, 0) and (x, y) . For example, if before = [[2, 3], [5, 7]] then after = [[2, 5], [7, 17]] , because after[0][0] = before[0][0] = 2 after[0][1] = before[0][0] + before[0][1] = 2 + 3 = 5 after[1][0] = before[0][0] + before[1][0] = 2 + 5 = 7 after[1][1] = before[0][0] + before[0][1] + before[1][0] + before[1][1] = 2 + 3 + 5 + 7 = 17 You are given the after matrix. Recover the before matrix that produced it. Input Format The first line contains two space-separated integers R and C , the number of rows and the number of columns of the matrix. Each of the next R lines contains C space-separated integers; the j -th value on the i -th of t