//时间复杂度为O(N)
#include<iostream>
using namespace std;
int max(int x, int y)
{
return (x > y) ? x : y;
}
int MaxSum(int Array[], int n)
{
int nStart = Array[n-1];
int nAll = Array[n-1];
for (int i = n-2; i >= 0; i--)
{
nStart = max(Array[i], Array[i] + nStart);
nAll = max(nStart, nAll);
}
return nAll;
}
int main(int argc, char *argv[])
{
int Array[6] = {1, -2, 3, 5, -3, 2};
int nAll = MaxSum(Array, 6);
cout<<nAll<<endl;
}