Suppose the company invests x of their surplus in the 5% rate (and thus 40000-x has 6.5%). Then we have that 5%*x+(40000-x)6.5%=6.25%*40000.
We have that solving this, 5%* x+40000*6.5%-6.5%*x =6.25%* 40000 Accumulating terms, 1.5%*x=0.25%*40000 x=40000/6= 6666.67$. We see that if we invest 6666.67$ at 5%, we get exactly the given rate. If we invest more, we obviously get less. Hence, we have that the company has to invest at 6.5% more than 40000-6666.67=33333.33$