Python Max Slice Sum
def max_slice_sum(a: list[int]) -> int:
tmp = max_sum = float("-inf")
for v in a:
tmp = max(tmp + v, v)
max_sum = max(max_sum, tmp)
return int(max_sum)
This is a Kadane-style scan: keep the best running sum and the best overall sum while moving once through the array.