← All problemsSign in

Minimize the Difference

CodeChefRating 3480Open on judge ↗

Chef has an array $A$ consisting of $N$ integers. Consider an array $S$ of length $N$, such that each $S_i$ is either $+1$ or $-1$. For such an array, we define $f(S)$ as follows: - Consider a $0$-indexed array $B$ of length $N+1$, where $B_0 = 0$ and for $1 \leq i \leq N$, $B_i = \sum_{j=1}^i S_j\cdot A_j$ Informally, $B$ is the *signed prefix sum* array of $A$, with $S$ giving the signs.

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