int countSubmatrices(int** grid, int gridSize, int* gridColSize, int k) {
int x=gridSize,y=*gridColSize;
int a[x][y];
memset(a,0,sizeof(a));
int count = 0;
for(int i=0;i<x;i++){
for(int j=0;j<y;j++){
if(i0){
if(j0)a[i][j]=grid[i][j];
else a[i][j]=a[i][j-1]+grid[i][j];
}
else{
if(j==0)a[i][j]=a[i-1][j]+grid[i][j];
else a[i][j]=a[i-1][j]+a[i][j-1]+grid[i][j]-a[i-1][j-1];
}
if(a[i][j]>k)break;
count++;
}
}
return count;
}