We are given 2D matrix array (let's say length i and wide j) and integer k We have to find size of smallest rectangle, that contains this or greater sum F.e k=7
4 1
1 1
1 1
4 4
Anwser is 2, because 4+4=8 >= 7, if there wasn't last line, anwser would be 4, 4+1+1+1 = 7 >= 7
My idea is to count prefix sums Pref[k,l]=Tab[k,l]+Pref[k-1,l]+Pref[k,l-1] And then compare every single rectangle
Is this possible to make it faster? My idea is T(n)=O(n^2) (Where n is number of elements in matrix) I would like to do this in time n or n * log n
I would be really glad if someone would give me any tip how to do this :)