merge sort greedy implementation