#C2249. HybridSort Algorithm

    ID: 45544 Type: Default 1000ms 256MiB

HybridSort Algorithm

HybridSort Algorithm

Alice has developed an innovative sorting algorithm called HybridSort. The algorithm works by combining two well‐known sorting methods: quicksort and merge sort. Given an array \(a\) of \(n\) integers and a threshold \(k\), the algorithm works as follows:

  • If \(n \le k\), then the array is sorted using quicksort.
  • If \(n > k\), then the array is sorted using merge sort.

Your task is to implement the HybridSort algorithm. The input will contain the number of integers and the threshold on the first line, followed by the list of integers on the second line. The output should be the sorted array in ascending order. For example, if the input is:

10 3
10 7 1 8 3 5 4 2 9 6

Then the output should be:

1 2 3 4 5 6 7 8 9 10

Note: All formulas are represented in \(\LaTeX\) format.

inputFormat

The first line contains two integers \(n\) and \(k\) where \(n\) is the number of elements in the array and \(k\) is the threshold for selecting the sorting algorithm. The second line contains \(n\) space-separated integers representing the array.

outputFormat

Output the sorted array in ascending order. The numbers should be separated by a space.

## sample
10 3
10 7 1 8 3 5 4 2 9 6
1 2 3 4 5 6 7 8 9 10