Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Choosing the asteroid to collide with can be done greedily.
If an asteroid will destroy the planet, then every bigger asteroid will also destroy the planet.
You only need to check the smallest asteroid at each collision. If it will destroy the planet, then every other asteroid will also destroy the planet.
Sort the asteroids in non-decreasing order by mass, then greedily try to collide with the asteroids in that order.