This problem requires the way of thinking.
1st, we should fix how long distance we keep.
2nd, we should fix how many balls we put in the array.
As for 2nd point, we can deny the unrealistic case by if sentence and some checking procesure.
What is important is Fixing and Checking.
Code is below.
- harmonic series diverges.
- more detail is here.