\begin{algorithm} \caption{Merge Sorted Lists} \begin{algorithmic} \INPUT $k$ sorted lists with $n$ elements in total \OUTPUT A sorted list of size $n$ \STATE extract the first element from each sorted list to form $A[1..k]$ \STATE $A.\text{heap-size} = k$ \STATE \CALL{BuildMinHeap}{$A$} \STATE let $L$ be the result list \WHILE {$A.\text{heap-size} \ne 0$} \STATE $x =$ \CALL{HeapExtractMin}{$A$} \STATE let $l$ be the list which $x$ came from \IF{$l$ \textbf{is} not empty} \STATE extrace the first element $y$ from $l$ \STATE \CALL{MinHeapInsert}{$A, y$} \ENDIF \STATE append $x$ to $L$ \ENDWHILE \RETURN $L$ \end{algorithmic} \end{algorithm}