Perhaps I'm missing something, but isn't the maximum of the cumulative sum simply the last value, ie. sum(x)? Hadley