current position:Home>The values ​​of b[i] are -1 2 4 3 5 respectively. This is what I use to find the maximum interval sum of consecutive numbers in the array. Shouldn't it be 14? Why do I calculate 25, and they all add up25

The values ​​of b[i] are -1 2 4 3 5 respectively. This is what I use to find the maximum interval sum of consecutive numbers in the array. Shouldn't it be 14? Why do I calculate 25, and they all add up25

2022-08-06 10:02:34CSDN Q&A

ans=b[1];sum=0
for(int i=1;i<=a;i++){
if(sum>0)sum+=b[i];
else sum=b[i];
if(sum>=ans)ans=sum;
if(sum

copyright notice
author[CSDN Q&A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/218/202207301853523466.html

Random recommended