A-B-C Sort Codeforces Solution | Codeforces Problem Solution 2022
D. A-B-C Sort
time limit per test
2 secondsmemory limit per test
256 megabytesinput
standard inputoutput
standard outputYou are given three arrays , and . Initially, array consists of elements, arrays and are empty.
You are performing the following algorithm that consists of two steps:
- Step : while is not empty, you take the last element from and move it in the middle of array . If currently has odd length, you can choose: place the element from to the left or to the right of the middle element of . As a result, becomes empty and consists of elements.
- Step : while is not empty, you take the middle element from and move it to the end of array . If currently has even length, you can choose which of two middle elements to take. As a result, becomes empty and now consists of elements.
Can you make array sorted in non-decreasing order?
Solution Click Below:- CLICK HERE
Input
The first line contains a single integer () — the number of test cases. Next cases follow.
The first line of each test case contains the single integer () — the length of array .
The second line of each test case contains integers () — the array itself.
It's guaranteed that the sum of doesn't exceed .
No comments:
Post a Comment