Approach hintTry it first, then revealHide
Deletions are hard to undo, but insertions are easy: process the destruction order in reverse. Each restored element unites with restored neighbours, the DSU keeps segment sums, and a running maximum gives each answer.