k way merge using a priority queue