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.




seq$ = "-1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1"
max = -999
for i = 1 to 11
sum = 0
   for j = i to 11
      sum = sum + val(word$(seq$,j,","))
      If sum > max then
         max = sum
         i1  = i
         j1  = j
      end if
   next j
next i
print "Sum:";
for i = i1 to j1
   print word$(seq$,i,",");",";
next i
print " = ";max