cumarr[-1] = 0for i = 0 to n-1 cumarr[i] = cumarr[i-1] + x[i] maxsofar = 0for i = 0 to n-1 for j = i to n-1 sum = cumarr[j] - cumarr[i-1] /* sum - сумма всех элементов x[i..j] */ maxsofar = max(maxsofar, sum)