$n = 2e4; @input = map int rand 1e5, 1 .. $n; $sums = zeroes long, scalar @input; $vec = pdl long, \@input; with_time { my @max = map +($sums( 0 : -$_ - 1 ) += $vec( $_ : -1 ))->maximum, 0 .. $#input };