#include<iostream>
#include<assert.h>
using namespace std;
int maxSum(int* a, int n)
{
    assert(a != NULL && n >= 1);
    int maxSum = a[0];
    int currentSum = a[0];
    for(int i = 0; i < n; i++)
    {
           
         if(currentSum <= 0)
            currentSum = a[i];
         else
             currentSum += a[i];
              
         if(currentSum > maxSum)
          maxSum = currentSum;
    }
      
    return maxSum;
        
}
int main()
{
     int a[] = {1, 2, 3, 10, -20, -100, 4, 20};
     cout<< maxSum(a, 8)<<endl;
      
     int b[] = {-1, -2, -3};
     cout<< maxSum(b, 3)<<endl;
      
    int c[] = {-1, 2, 3, -5, 6, -6, 7, 1, - 10, 3};
    cout<< maxSum(c, 10)<<endl;
    return 0;
}