最大子序列和
直接上O(n
)
ll max_sum (int a[], int n) {
ll s = 0;
ll sum = 0;
for (int i = 0; i < n; i ++) {
if(sum >= 0)
sum += a[i];
else
sum = a[i];
if(sum > s)
s = sum;
}
return s;
}
ll max_sum (int a[], int n) {
ll s = 0;
ll sum = 0;
for (int i = 0; i < n; i ++) {
if(sum >= 0)
sum += a[i];
else
sum = a[i];
if(sum > s)
s = sum;
}
return s;
}