D. Move Back at a Cost time limit per test2 seconds memory limit per test256 megabytes…
- User
D. Move Back at a Cost time limit per test2 seconds memory limit per test256 megabytes
You are given an array of integers a of length n . You can perform the following operation zero or more times:
In one operation choose an index i (1≤i≤n ), assign ai:=ai+1 , and then move ai to the back of the array (to the rightmost position). For example, if a=[3,5,1,9] , and you choose i=2 , the array becomes [3,1,9,6] . Find the lexicographically smallest∗ array you can get by performing these operations.
∗ An array c is lexicographically smaller than an array d if and only if one of the following holds:
c is a prefix of d , but c≠d ; or in the first position where c and d differ, the array c has a smaller element than the corresponding element in d . Input Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104 ). The description of the test cases follows.
The first line contains a single integer n (1≤n≤105 ), the length of the array.
The second line contains n integers a1,a2,…,an (1≤ai≤109 ), the elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 105 .
Output For each test case, print the lexicographically smallest array you can get.
Example InputCopy 3 3 2 1 3 5 1 2 2 1 4 6 1 2 3 6 5 4 OutputCopy 1 3 3 1 1 3 3 5 1 2 3 4 6 7 please give corerct c++ code all tests pass please
- Assistant