The required minimum is n=2k+k−1.
In this case the game can be played indefinitely by choosing the last k+1 boxes, b2k−1,b2k,…,b2k+k−1, at each step: At step r, if box b2k+i−1 has exactly mi coins, then ⌈mi/2⌉ coins are removed from that box, unless i≡r−1(modk+1), in which case 2k+i−1 coins are added. Thus, after step r has been performed, box b2k+i−1 contains exactly ⌈mi/2⌉ coins, unless i≡r−1(modk+1), in which case it contains exactly mi+2k+i−1 coins. This game goes on indefinitely, since each time a box is supplied, at least 2k−1 coins are added, so it will then contain at least 2k coins, good enough to survive the k steps to its next supply.
We now show that no smaller value of n works. So, let n≤2k+k−2 and suppose, if possible, that a game can be played indefinitely. Notice that a box currently containing exactly m coins survives at most w=⌈log2m⌉ withdrawals; this w will be referred to as the weight of that box. The sum of the weights of all boxes will referred to as the total weight. The argument hinges on the lemma below, proved at the end of the solution.
Lemma. *Performing a step does not increase the total weight. Moreover, supplying one of the first 2k−2 boxes strictly decreases the total weight.*
Since the total weight cannot strictly decrease indefinitely, n>2k−2, and from some stage on none of the first 2k−2 boxes is ever supplied. Recall that each step involves a (k+1)-box choice. Since n≤2k+k−2, from that stage on, each step involves a withdrawal from at least one of the first 2k−2 boxes. This cannot go on indefinitely, so the game must eventually come to an end, contradicting the assumption.
Consequently, a game that can be played indefinitely requires n≥2k+k−1.
Proof of the Lemma. Since a withdrawal from a box decreases its weight by at least 1, it is sufficient to show that supplying a box increases its weight by at most k; and if the latter is amongst the first 2k−2 boxes, then its weight increases by at most k−1. Let the box to be supplied be bi and let it currently contain exactly mi coins, to proceed by case analysis:
If mi=1, the weight increases by ⌊log2(i+1)⌋≤⌊log2(2k+k−1)⌋≤⌊log2(2k+1−2)⌋≤k; and if, in addition, i≤2k−2, then the weight increases by ⌊log2(i+1)⌋≤⌊log2(2k−1)⌋=k−1.
If mi=2, then the weight increases by ⌊log2(i+2)⌋−⌊log22⌋≤⌊log2(2k+k)⌋−1≤k−1.
If mi≥3, then the weight increases by
⌊log2(i+mi)⌋−⌊log2mi⌋≤⌊log2(i+mi)−log2mi⌋+1≤⌊log2(1+32k+k−2)⌋+1≤k,
since 1+31(2k+k−2)=31(2k+k+1)<31(2k+2k+1)=2k.
Finally, let i≤2k−2 to consider the subcases mi=3 and mi≥4. In the former subcase, the weight increases by
⌊log2(i+3)⌋−⌊log23⌋≤⌊log2(2k+1)⌋−1=k−1,
and in the latter by
⌊log2(i+mi)⌋−⌊log2mi⌋≤⌊log2(i+mi)−log2mi⌋+1≤⌊log2(1+42k−2)⌋+1≤k−1,
since 1+41(2k−2)=41(2k+2)<2k−2+1. This ends the proof and completes the solution.