← All problemsSign in

Summing the values

CodeChefRating 2702Open on judge ↗

For an array $B$ of length $M$, we define its *value* $f(B)$ as follows: $$ f(B) = \sum_{i=1}^{M-1} \left( \left( \sum_{j=1}^i B_j\right) - \left( \sum_{j=i+1}^M B_j \right) \right) $$ In particular, if $M = 1$ then $f(B) = 0$. You're given an array $A$ of length $N$. Find the sum of *values* of all of its subarrays. That is, compute $$ \sum_{L=1}^N \sum_{R=L}^N f(A[L\ldots R]) $$ where $A[L

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start