This is a maximum sum subarray problem.