Answer
$
w=C T_{a f}\left(1-\frac{\sqrt{T_0}}{\sqrt{T_{\text {af }}}}\right)^2
$
Work Step by Step
$$
\dot{Q}=\dot{m}\left(h_e-h_i\right)=\dot{m} C\left(T_p-T_u\right)
$$ where $\dot{Q}$ is the negative of the heat supplied to the heat engine. That is, $$
\dot{Q}_H=-\dot{Q}=\dot{m} C\left(T_a-T_p\right)
$$ Then the work output of the Carnot heat engine can be expressed as $$
\dot{W}=\dot{Q}_H\left(1-\frac{T_0}{T_F}\right)=\dot{m} C\left(T_{a f}-T_p\right)\left(1-\frac{T_0}{T_p}\right).
$$ Taking the partial derivative of $\mathrm{W}$ with respect to $T_p$ while holding $T_{\mathrm{af}}$ and $T_{\mathrm{o}}$ constant gives $$
\frac{\partial W}{\partial T_p}=0 \longrightarrow-\dot{m} \mathrm{C}\left(1-\frac{T_0}{T_p}\right)+\dot{m} C\left(T_p-T_{\mathrm{af}}\right) \frac{T_0}{T_p^2}=0
$$ Solving for $T_p$ we obtain $$
T_p=\sqrt{T_0 T_{\mathrm{af}}}
$$ which the temperature at which the work output of the Carnot engine will be a maximum. The maximum work output is determined by substituting the relation above into Eq. (1), $$
\dot{W}=\dot{m} C(T_{\text {af }}-T_p)\left(1-\frac{T_0}{T_p}\right)=\dot{m} C\left(T_{\text {af }}-\sqrt{T_0 T_{a f}}\right)\left(1-\frac{T_0}{\sqrt{T_0 T_{\text {af }}}}\right).
$$ It simplifies to $$
\dot{W}=\dot{m} C T_{\text {af }}\left(1-\frac{\sqrt{T_0}}{\sqrt{T_{\text {af }}}}\right)^2
$$ or $$
w=C T_{a f}\left(1-\frac{\sqrt{T_0}}{\sqrt{T_{\text {af }}}}\right)^2
$$ This is the desired relation.