kadane algorithm with negative numbers included as sum code example
Example: kadane algorithm with negative numbers included as sum
//Usually Kadene's algorithm is not considered for negative numbers.
int ms,cs;
ms=cs=a[0];
for(int i=1;i<n;i++)
{
cs=max(a[i],cs+a[i]);
ms=max(cs,ms);
}
return ms;