Hints: Array Splitting
a b c d e
Consider any random partition and compress all elements in a segment with its sum.
Express
Hence, the cost is just the sum of
Just sort the suffix sum array and pick the maximum elements from the suffix array. There’s a small catch.
The first suffix sum necessarily needs to be taken. The rest elements can be chosen freely.