Solution (source code)

= Solution

If $S_k<n\le S_{k+1}$, the construction gives $X_n=S_{k+1}-n$. This is exactly the stated maximum over the next renewal endpoint.