In the Grand Archives of Prime City, the Archivist faces a massive file of numbers ÔÇö too large to fit in memory. The external sort algorithm divides the file into chunks that fit in memory, sorts each chunk, writes them to temporary files, then merges them using a k-way merge. "External sort is for when data doesn't fit in RAM," the Archivist explains. "Sort chunks of size M in memory, write each sorted chunk to disk, then merge all chunks using a min-heap. The simulation here uses a smaller scale." Given N integers and a chunk size M, simulate external sort: divide the array into chunks of size M, sort each chunk, then merge all sorted chunks. Output the final sorted array. Constraints: 1 <= N <= 10^5, 1 <= M <= N Input: 7 5 1 3 7 2 6 4 3 Output: 1 2 3 4 5 6 7 Input: 5 5 4 3 2 1 2 Output: 1 2 3 4 5
Constraints:
1 <= N <= 10^5, 1 <= M <= N
Tags:
