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 2 of 5: Define the prefix-sum potential
Detailed analysis
Set . It is zero exactly when all are zero. A move across edge for changes only the th prefix sum, and hence changes by one.