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.




100 PROGRAM "Subseq.bas"
110 RANDOMIZE 
120 NUMERIC A(1 TO 15)
130 PRINT "Sequence:"
140 FOR I=LBOUND(A) TO UBOUND(A)
150   LET A(I)=RND(11)-6
160   PRINT A(I);
170 NEXT 
180 LET MAXSUM,ST=0:LET EN=-1
190 FOR I=LBOUND(A) TO UBOUND(A)
200   LET SUM=0
210   FOR J=I TO UBOUND(A)
220     LET SUM=SUM+A(J)
230     IF SUM>MAXSUM THEN LET MAXSUM=SUM:LET ST=I:LET EN=J
240   NEXT 
250 NEXT 
260 PRINT :PRINT "SubSequence with greatest sum:"
270 IF ST>0 THEN PRINT TAB(ST*3-2);
280 FOR I=ST TO EN
290   PRINT A(I);
300 NEXT 
310 PRINT :PRINT "Sum:";MAXSUM