The system is kept rest in the horizontal position and a particle P falls from a height h and collides with B and sticks to it.

Therefore angular momentum of the rod just after the collision
When the mass 2m will at the top most position and the mass m at the lowest point, they will automatically rotate. In this position the total gain in potential energy = 2 mg × (l/2) – mg (l/2) = mg(l/2)

