Consider any random partition and compress all elements in a segment with its sum.
$$\sum f(i) = a + 2 \cdot b + 3 \cdot c + 4 \cdot d + 5 \cdot e$$
Express $\sum f(i)$ using suffix sums. Assume $S_c$ denotes suffix sum starting from the segment containing $c$.