IOITC Day-1 Part-3
Given a grid of integers L = [[A1,1, A1,2, A1,3, ..., A1,M], [A2,1, A2,1, A2,3, ..., A2,M], [A3,1, A3,2, A3,3, ..., A3,M], [..., ..., ..., ..., ...], [AN,1, AN,2, AN,3, ..., AN,M]]. Where Ai,j ≥ 0 , 0 ≤ i ≤ N, 0 ≤ j ≤ M. You have to find least perimeter of rectangle which adds up to a given integer K.
For example,
If L = [[1, 0, 0, 0, 0], [0, 0, 0, 0, 0], [1, 0, 1, 1, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 2], [1, 0, 0, 0, 0]] and K = 3 , The answer would be 22, rectangles will be {(0, 0), (2, 2)} and {(2, 3), (4, 4)}.