Height of the ceiling, H=25 m
Initial speed of the ball, u=40 m/s.
We know that maximum height obtained by a projectile is given by:
h0=u2sin2θ2g
If the projectile just grazes the ceiling (without hitting it),
25=(40)2sin2θ2×10
or sin2θ=25×2×1040×40=516
⇒sinθ=√516=√54 and cosθ=√114
Then, horizontal range of the ball is given by
R=u2×sin2θg=u2×2sinθcosθg
=1600×2×√5×√1116×10=1483.2310=148.32 m