Joining the Ropes — Solution & Editorial
Huffman-style greedy: always join the two shortest ropes (min-heap); their combined length re-enters the pool.
Complexity: O(N log N)
Watch out: Total cost reaches ~106·log·N — 64-bit.
Huffman-style greedy: always join the two shortest ropes (min-heap); their combined length re-enters the pool.
Complexity: O(N log N)
Watch out: Total cost reaches ~106·log·N — 64-bit.