MathLabs

Problem 5

nn people are seated in a circle. A total of nknk 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 1 of 5: Encode the imbalance
di=ci−k,∑i=1ndi=0d_i=c_i-k,\qquad\sum_{i=1}^nd_i=0
Detailed analysis

Label people cyclically, let cic_i be the initial coin count, and set di=ci−kd_i=c_i-k. Since the total is nknk, ∑i=1ndi=0\sum_{i=1}^nd_i=0. Relabel so that d1≥0d_1\ge0.