python function to do the merging for an array containing a bunch of already sorted arrays