#C9074. Sort Nearly Sorted Array

    ID: 53127 Type: Default 1000ms 256MiB

Sort Nearly Sorted Array

Sort Nearly Sorted Array

Problem Description:

You are given a nearly sorted array where each element is at most (K) positions away from its target position. In other words, for an element whose index in the sorted array is (j) and in the given array is (i), it holds that (|i - j| \le K). Your task is to efficiently sort this array in ascending order.

inputFormat

Input Format:
- The first line contains two integers (N) and (K) where (N) is the number of elements in the array and (K) is the maximum distance an element is away from its target position.
- The second line contains (N) space-separated integers representing the array.

outputFormat

Output Format:
Output the sorted array as a sequence of numbers in one line separated by spaces.## sample

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

</p>