← All problemsSign in

Move Negative Stones

CodeChefRating 2976Open on judge ↗

You’re given an array $A$ containing $N$ integers. Your task is to make $A_i \geq 0$ for all $1 \leq i \leq N$. To achieve that, you can perform the following operation: - Choose an index $i$ ($1 \le i \lt N$) and any integer $X$ ($X$ can be negative); - Subtract $X$ from $A_i$ and add $X$ to $A_{i+1}$. That is, set $A_i:= A_i - X$ and $A_{i+1} := A_{i+1} + X$. Find the **minimum** number of

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