#C10750. Sort by Absolute Index Difference

    ID: 39990 Type: Default 1000ms 256MiB

Sort by Absolute Index Difference

Sort by Absolute Index Difference

You are given multiple test cases. In each test case, an array of integers is provided. Your task is to rearrange the array such that each element is moved to a position where its absolute difference with the index is minimized. It can be shown that simply sorting the array in non-decreasing order achieves this.

More formally, let \(A = [a_0, a_1, \dots, a_{n-1}]\) be the original array and \(A' = [a'_0, a'_1, \dots, a'_{n-1}]\) be its sorted version in ascending order. The optimality condition can be written as minimizing the absolute differences:

[ \sum_{i=0}^{n-1} \left|a'_i - i\right| ]

Although the above expression is provided for insight, the problem simply requires you to sort each given array and output the sorted order.

inputFormat

The first line of input contains a single integer \(T\) representing the number of test cases. Each test case is described over one line as follows:

  • The test case starts with an integer \(n\) indicating the number of elements in the array.
  • Then follows \(n\) space-separated integers representing the array elements.

All input should be read from stdin.

outputFormat

For each test case, output a single line containing the sorted array (in non-decreasing order). The elements should be separated by a single space. All output should be written to stdout.

## sample
2
4 4 3 1 2
5 10 -3 5 0 1
1 2 3 4

-3 0 1 5 10

</p>