#C12373. Merge Sort Algorithm

    ID: 41793 Type: Default 1000ms 256MiB

Merge Sort Algorithm

Merge Sort Algorithm

This problem requires you to implement the merge sort algorithm. Merge sort is a classic divide and conquer sorting algorithm with a time complexity of \(O(n\log n)\). You are required to sort a given list of integers in ascending order. The merge sort algorithm works by dividing the list into two halves, recursively sorting the halves, and then merging the sorted halves together.

Detailed Explanation:

  • Divide: The list is divided into two halves.
  • Conquer: Recursively sort each half.
  • Combine: Merge the two sorted halves into one sorted sequence. The merging process involves comparing the smallest unmerged elements in each half and adding the smaller element into the new list.

Remember that you must implement the merge sort using the merge function to combine two sorted lists.

inputFormat

The input is read from stdin and consists of two lines:

  1. The first line contains a single integer \(n\) representing the number of elements.
  2. The second line contains \(n\) space-separated integers.

outputFormat

Output the sorted list of integers in ascending order to stdout as a single line, with each number separated by a space.

## sample
6
34 7 23 32 5 62
5 7 23 32 34 62