#include <iostream>
#include <cstdio>
using namespace std;
int MaxSumSum(int n, int a[]) {
int i, sum = 0, b = 0;
for (i = 0; i < n; i++) {
if (b > 0) //b依然大于零,说明前面的子段可以继续用
b += a[i];
else //如果b<0,前面那一串子段可以抛弃了
b = a[i];
if (b > sum)
sum = b; //sum墙头草,谁大跟谁
}
return sum;
}
int main() {
int a[6] = { 1,2,-5,-2,11,-1 }; //以此为例
int n = 6;
int sum = MaxSumSum(n, a);
cout << sum << endl;
return 0;
}
02-08
02-08