Task

Given a sequence of integers, find a continuous subsequence which maximizes the sum of its elements, that is, the elements of no other single subsequence add up to a value larger than this one.



An empty subsequence is considered to have the sum of   0;   thus if all elements are negative, the result must be the empty sequence.




10 DATA 12,0,1,2,-3,3,-1,0,-4,0,-1,-4,2
20 DATA 11,-1,-2,3,5,6,-2,-1,4,-4,2,-1
30 DATA 5,-1,-2,-3,-4,-5
40 FOR n=1 TO 3
50 READ l
60 DIM a(l)
70 FOR i=1 TO l
80 READ a(i)
90 PRINT a(i);
100 IF i<l THEN PRINT ", ";
110 NEXT i
120 PRINT 
130 LET a=1: LET m=0: LET b=0
140 FOR i=1 TO l
150 LET s=0
160 FOR j=i TO l
170 LET s=s+a(j)
180 IF s>m THEN LET m=s: LET a=i: LET b=j
190 NEXT j
200 NEXT i
210 IF a>b THEN PRINT "[]": GO TO 280
220 PRINT "[";
230 FOR i=a TO b
240 PRINT a(i);
250 IF i<b THEN PRINT ", ";
260 NEXT i
270 PRINT "]"
280 NEXT n