[-1, 3, -1, 5]
| |cur_val=3 | cur_val=-1
cur_sum(初始化 ) cur_sum=-1 <0 (没有贡献) | cur_sum=3>0 (有贡献)
max_sum(初始化 ) 重新计算cur_sum,因此cur_sum=cur_val =3 | cur_sum=cur_sum+cur_val =3-1=2
max_sum=max(max_sum,cur_sum)=3 |max_sum=max(max_sum,cur_sum)=max(3,2)=3
step 1 step2 step3 .......
def maxsumlist(n,l):
currsum=l[0]
maxsum=l[0]
for i in range(1,n):
if currsum>0:
currsum+=l[i]
else:
currsum=l[i]
maxsum=max(currsum,maxsum)
return(maxsum)
n=int(input())
list_a=[int(i) for i in input().strip("[]").split(" ")]#convert string of list to list
print(maxsumlist(n, list_a))
currsum=l[0]
maxsum=l[0]
for i in range(1,n):
if currsum>0:
currsum+=l[i]
else:
currsum=l[i]
maxsum=max(currsum,maxsum)
return(maxsum)
n=int(input())
list_a=[int(i) for i in input().strip("[]").split(" ")]#convert string of list to list
print(maxsumlist(n, list_a))