Algorithm:
Maximum-Sum Contiguous Subvector

/* Precondition: x[1..n] is an array of floating-point (real) numbers. */

procedure MaxSumContigVector (x[1..n]: float)
// Returns the maximum sum of a continuous subarray drawn from x.
MaxSoFar := 0.0
MaxEndingHere := 0
i := 1
while i ≠ n + 1 do
MaxEndingHere := max(0.0, MaxEndingHere + x[i])
MaxSoFar := max(MaxSoFar, MaxEndingHere)
i := i + 1
end
return MaxSoFar

/* Postcondition: MaxSoFar is the maximum sum of any contiguous subvector in x[1..n]. */