Problem 5
people are seated in a circle. A total of coins are distributed among them, not necessarily equally. A move transfers one coin between two adjacent people. Find an algorithm using the minimum number of moves that leaves everyone with the same number of coins.
Step 4 of 5: Handle the zero-prefix case
Detailed analysis
In the zero-prefix case, choose the first with . Such a exists because the total deviation is zero. Transfer one coin from to ; the negative prefix through moves one unit toward zero, so decreases by one. The chosen move keeps .