You are given an array of integers 𝑎 of length 𝑛. You can perform the following…
- User
You are given an array of integers 𝑎 of length 𝑛. You can perform the following operation zero or more times:
In one operation choose an index 𝑖 (1≤𝑖≤𝑛), assign 𝑎𝑖:=𝑎𝑖+1, and then move 𝑎𝑖 to the back of the array (to the rightmost position). For example, if 𝑎=[3,5,1,9], and you choose 𝑖=2, the array becomes [3,1,9,6]. Find the lexicographically smallest∗ array you can get by performing these operations.
∗An array 𝑐 is lexicographically smaller than an array 𝑑 if and only if one of the following holds: 𝑐 is a prefix of 𝑑, but 𝑐≠𝑑; or in the first position where 𝑐 and 𝑑 differ, the array 𝑐 has a smaller element than the corresponding element in 𝑑. Input Each test contains multiple test cases. The first line contains the number of test cases 𝑡 (1≤𝑡≤104). The description of the test cases follows.
The first line contains a single integer 𝑛 (1≤𝑛≤105), the length of the array.
The second line contains 𝑛 integers 𝑎1,𝑎2,…,𝑎𝑛 (1≤𝑎𝑖≤109), the elements of the array.
It is guaranteed that the sum of 𝑛 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 . #include #include #include
using namespace std;
// const int N = 2e5 + 5; // int a[N]; typedef long long ll; typedef vector vi; #define endl '\n'
void solve() { //your code here
}
int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while(t--) solve(); }
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.