How to determine the max offset of a value, given the range, step size and amount of steps
Suppose we start at $s$ and want to end up at $e$. We take $n$ steps, $n^+$ positive steps and $n^-$ negative steps. Then we can reach maximum $m \in[s, s + n^+\delta]$ and can end up in $[m-n^-\delta, m]$. We get equations:
\begin{align}
n &amp;= n^+ + n^-\\
n^+ &amp;\geq 0\\
n^- &amp;\geq 0\\
s &amp;\leq m \leq s+n^+\delta\\
m-n^-\delta &amp;\leq e \leq m\\
\end{align}
Rearranging we get our upper bounds:
\begin{align}
m &amp;\leq s+n^+\delta\\
m&amp;\leq e+n^-\delta\\
\end{align}
Substitute and realize maximum:
\begin{align}
m &amp;= \min(s+n^+\delta, e+n\delta - n^+\delta)\\
m &amp;= s + \min(n^+\delta, e-s+n\delta - n^+\delta)
\end{align}
This looks complicated, but set $x = n^+\delta$ and $c = e-s+n\delta$ you only need to solve how to maximize:
$$\min(x, c - x)$$
Can you take it from here?