#K92687. Unusual Block Sort

    ID: 38253 Type: Default 1000ms 256MiB

Unusual Block Sort

Unusual Block Sort

Given an array of integers and a block size \(k\), partition the array into consecutive blocks each of size \(k\) (the last block may have fewer than \(k\) elements). Sort each block individually in non-decreasing order and then output the entire array by concatenating these sorted blocks.

For example, if the array is [4, 2, 1, 6, 5, 3, 7] with \(k=3\), the blocks are [4, 2, 1], [6, 5, 3], and [7]. Sorting each block gives [1, 2, 4], [3, 5, 6], and [7] respectively, and merging them results in [1, 2, 4, 3, 5, 6, 7].

inputFormat

The first line contains two integers (n) and (k) (where (n) is the number of elements in the array, and (k) is the block size). The second line contains (n) space-separated integers representing the array.

outputFormat

Output a single line containing (n) space-separated integers, representing the array after applying the block-wise sort and merging the blocks.## sample

7 3
4 2 1 6 5 3 7
1 2 4 3 5 6 7