My solution is as follows but I am not getting desired result. Can you please help?
#include
#include
using namespace std;
int maxSum_submatrix( int a[][100], int rows, int cols){
//Column wise addition first:
for (int r = rows - 1; r>=0; r--){
for (int c = cols -2; c>=0; c--){
a[r][c] += a[r][c+1];
}
}
// Row wise addition:
for (int c = cols -1; c>=0; c--){
for (int r = rows -2; r>=0; r--){
a[r][c] += a[r+1][c];
}
}
int maxSum = INT_MIN;
for (int i=0; i<rows; i++){
for (int j=0; j<cols; j++){
maxSum = max(maxSum, a[i][j]);
}
}
return maxSum;
}
int main(){
int a[100][100] = {0};
int rows,cols;
cin>>rows>>cols;
for (int i=0; i<rows; i++){
for (int j=0; j<cols; j++){
cin>>a[rows][cols];
}
}
cout<<maxSum_submatrix(a, rows, cols)<<endl;
return 0;
}