You are given an array of size . Each element in this array is an integer between and .
You can perform several operations to this array. During an operation, you can replace an element in the array with any integer between and .
Output the minimum number of operations needed such that the resulting array doesn't contain any local maximums, and the resulting array after the operations.
An element is a local maximum if it is strictly larger than both of its neighbors (that is, and ). Since and have only one neighbor each, they will never be a local maximum.
Each test contains multiple test cases. The first line will contain a single integer — the number of test cases. Then test cases follow.
The first line of each test case contains a single integer — the size of the array .
The second line of each test case contains integers , the elements of array.
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, first output a line containing a single integer — minimum number of operations required. Then ouput a line consist of integers — the resulting array after the operations. Note that this array should differ in exactly elements from the initial array.
If there are multiple answers, print any.
5 3 2 1 2 4 1 2 3 1 5 1 2 1 2 1 9 1 2 1 3 2 3 1 2 1 9 2 1 3 1 3 1 3 1 3
0 2 1 2 1 1 3 3 1 1 1 2 2 2 1 2 1 2 3 3 2 3 3 2 1 2 2 1 3 3 3 1 1 1 3
In the first example, the array contains no local maximum, so we don't need to perform operations.
In the second example, we can change to , then the array don't have local maximums.
0 Comments
If you have any doubts/suggestion/any query or want to improve this article, you can comment down below and let me know. Will reply to you soon.