Maximum range of a projectile (launched from an elevation)

As you described, we substitute $y=0$ and $x=R$ into the trajectory equation: $$0=H+R\tan{\theta}-R^2\frac{g}{2u^2}\sec^2\theta.\tag{1}$$ Then, differentiating with respect to $\theta$ and setting $\frac{dR}{d\theta}=0$:

$$0=R_{max}\sec^2\theta-R_{max}^2\frac{g}{2u^2}2\sec^2\theta\tan\theta,$$ which simplifies to $$R_{max}=\frac{u^2}{g}\cot\theta.\tag{2}$$ Solving $(1)$ and $(2)$ will yield the desired expressions for $\theta$ and $R_{max}$.


Adapting concepts from the question and solutions here, we have

$$R_\text{max}=\frac {uw}g=\color{red}{\frac ug\sqrt{u^2+2gH}}$$ and $$\tan\theta^*=\frac {\ell-H}{\sqrt{\ell^2-H^2}} =\frac {\frac {u^2}g}{\frac ug \sqrt{u^2+2gH}}=\color{red}{\frac u{\sqrt{u^2+2gH}}}$$ where $\ell$ is the linear distance between the launch and end points of the projectile.

Addendum:

Here $\tan\theta^*$ was derived using $\theta^*=\frac \pi 4+\frac\alpha 2$, which leads to $$\tan\theta^*=\frac {1+\sin\alpha}{\cos\alpha}=\frac {\ell (1+\sin\alpha)}{\ell\cos\alpha}=\frac{\ell -H}{R_{\text{max}}}$$ as $\alpha$ is negative in this case.