Solution (source code)

= Solution

Complete the square in the velocity variable:
$$
H=V(x)+pv-\frac12mv^2
=V(x)+\frac{p^2}{2m}-\frac m2\left(v-\frac pm\right)^2.
$$
Since $m>0$, the final term is nonpositive and vanishes at exactly one velocity. Therefore
$$
\boxed{v_*=\frac pm,\qquad H_{\max}(x,p)=\frac{p^2}{2m}+V(x).}
$$
This is the <Legendre transform in mechanics> that constructs the <Hamiltonian mechanics> energy from the kinetic-minus-potential Lagrangian.