TLE please help someone


#1

int n = B.size();
int m = B[0].size();
int array[A+1][n][m];
memset(array,0,sizeof(array));

for(int k=0 ; k<=A ; k++)
{
    for(int i=0 ; i<n ; i++)
    {
        for(int j=0 ; j<m ; j++)
        {
            if(k==0)
            {
                array[0][i][j] = B[i][j];
            }
            else
            {
                int curr = INT_MIN;
                if(i>0)
                {
                    curr = max(curr,array[k-1][i-1][j]);
                }
                if(j>0)
                {
                    curr = max(curr,array[k-1][i][j-1]);
                }
                if(i<n-1)
                {
                    curr = max(curr,array[k-1][i+1][j]);
                }
                if(j<m-1)
                {
                    curr = max(curr,array[k-1][i][j+1]);
                }
                
                array[k][i][j] = max(curr,array[k-1][i][j]);
            }
        }
    }
}

vector<vector<int> > v1;
for(int i=0 ; i<n ; i++)
{
    for(int j=0; j<m ; j++)
    {
        v1[i].push_back(array[A][i][j]);
    }
}

return v1;