Use a max-heap to always get the two heaviest stones:
Insert all stones into a max-heap.
While heap has more than one stone: - Extract the two largest: and (with ) - If , insert back into the heap
Return the remaining stone's weight, or if empty. Each smash involves at most two extractions and one insertion: per turn, at most turns. Time: . Space: .