for 507, kadane's 1d max sum in linear time