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.




[ -1 -2 3 5 6 -2 -1 4 -4 2 -1 ] as $seq
 
1 31 shl as $max
 
0   $seq length   1 range each as $i
    0 as $sum
    $i   $seq length  1 range each as $j
        $seq $j get   $sum +  as $sum
        $sum $max > if
            $sum as $max
            $i as $i1
            $j as $j1
 
"Sum: " print
$i1 $j1 1 range each
    #dup "$seq[%d]\n" print
    $seq swap get "%d," print
$max   $seq $j1 get   "%d  =  %d\n" print