My code above on the search for the maximum sum of sub-matrix and search for the beginning index, the end index of this sub-matrix.

```
int Max(int a,int b){return (a>b)?a:b;}
int Max(int a,int b,int c){return Max(Max(a,b),c);}
int MaxAcrossSubArray(int arr(),int l,int m,int r,int &Start,int &End)
{
Start=m;//initialize start index
int sum=arr(m);
int sum_l=arr(m);
for(int i=m-1;i>=l;--i)//include mid(---------|)
{
sum+=arr(i);
if(sum>sum_l)
{
Start=i;
sum_l=sum;
}
}
End=m+1;//initialize end index
sum=arr(m+1);
int sum_r=arr(m+1);
for(int i=m+2;i<=r;++i)//include mid(|-----------------)
{
sum+=arr(i);
if(sum>sum_r){
End=i;
sum_r=sum;
}
}
return sum_l+sum_r;//(-----------|---------------------)
}
int MaxSubArray(int arr(),int l,int r,int &Start,int &End)
{
if(l==r)
{
Start=l;
End=r;
return arr(l);
}
else
{
int mid=(l+r)/2;
int sA=-1,eA=-1,sB=-1,eB=-1,sC=-1,eC=-1;
int a=MaxSubArray(arr,l,mid,sA,eA);
int b=MaxSubArray(arr,mid+1,r,sB,eB);
int c=MaxAcrossSubArray(arr,l,mid,r,sC,eC);
int Maximum=Max(a,b,c);
if(Maximum==a)
{
Start=sA;
End=eA;
return a;
}
else if(Maximum==b)
{
Start=sB;
End=eB;
return b;
}
else
{
Start=sC;
End=eC;
return c;
}
}
}
}
int main()
{
int arr(9)={-2, 1, -3, 4, -1, 2, 1, -5, 4};
int Start=-1;
int End=-1;
cout<
```

```
```My algorithm works well in all cases, but I still need you to help me improve my algorithm to make it better. Is there a way to improve it?

```
```