Solution. Consider
am={1,0,the t-th student is a girl, where t≡m(mod2n+1),otherwise.
Consider bi=ai+ai−k−1−1∈{−1,0,1}. It is easy to see that for all m,
bm+1+⋯+bm+2n+1=2(a1+⋯+a2n+1)−(2n+1)=2(n+1)−(2n+1)=1.(1)
Note that this means there exists i0 such that bi0=1. If we can find i satisfying
bi=1andbi+1+bi+2+⋯+bi+k≥0,(2)
then ai=1 and
(ai−k+⋯+ai−1)+(ai+1+⋯+ai+k)≥k,
and thus the original problem is proved.
We use proof by contradiction to show that an i satisfying (2) exists. Suppose that for all i satisfying bi=1, bi+1+bi+2+⋯+bi+k is always negative. Take any one of these i0, and for all j, define ij to be the smallest integer satisfying ij>ij−1+k and bij=1. Take any two among {i0,i1,⋯,i2n+1} that are congruent modulo 2n+1, and without loss of generality assume these are i0 and iT.
Now, note that for all 0≤j≤T−1, by the definition of ij, bij+k+1 through bij+1−1 must all be ≤0. By the assumption for contradiction, this means
Sj:=bij+⋯+bij+1−1≤bij+⋯+bij+k=bij+(bij+1+⋯+bij+k)<1+0=1,
and thus Sj≤0. But on the other hand, since (2n+1)∣(iT−i0), (1) implies that
S0+⋯+ST−1=i=i0∑iT−1bi=2n+1iT−i0>0,
a contradiction! Hence there exists i satisfying (2). This completes the proof.