题解 | #最大连续子序列# 给大伙写个简单的
最大连续子序列
https://www.nowcoder.com/practice/afe7c043f0644f60af98a0fba61af8e7
import sys while True: try: n = int(input()) except: exit() if not n: break nums = list(map(int,input().split())) if all(_<0 for _ in nums): print(0,nums[0],nums[-1]) continue minPre,pre,res = 0,0,-1 start,end,t = -1,0,-1 for i,num in enumerate(nums): pre+=num if pre-minPre>res: res=pre-minPre start=t end=i if pre<minPre: t=i minPre=pre print(res,nums[start+1],nums[end])