Eliminating Balls With Merging (Hard Version)

Problem Name:
Eliminating Balls With Merging (Hard Version)
Site:CodeForces
Links:
Tags:
Problem setters: