求数组(元素可为正数、负数、0)的最大子序列和
int maxSum(int a[], int n)
{
int max = a[0];
int total = a[0];
for (int i = 1; i < n; i++)
{
if (total <= 0)
{
total = a[i];
}
else
{
total += a[i];
}
if (total > max)
{
max = total;
}
}
return max;
}