1)let us construct a min heap with all the top elements of k stacks.==>O(k)
2)extract min and add it to queue, then insert the next element of stack into min heap ==>O(logk)+O(1)+O(logk)
so total n extract-mins,n insertions into queue, n-k insertions into min heap.
total complexity: O(k)+O(nlogk)+O(n)+O((n-k)*logk)
i.e O(nlogk)