Problem
Consider a certain permutation of integers from to as and reverse of array as , that is, . You are given the inversions at each position of array and as and respectively.
Find the original array . If, there are multiple solutions, print any of them. If there is no solution, then print -1.
Note: The inversion of array for position is defined as the count of positions satisfying the following condition and .
Input format
- The first line contains denoting the number of test cases.
- For each test case:
- The first line contains denoting the number of elements.
- The second line contains the elements .
- The third line contains the elements .
Output format
For each test case, print the array in the space-separated format or -1 if no solution exists. Each test case should be answered in a new line.
Constraints
For first test case
Consider permutation .
It can be seen that inversion for this array will be as:
- For i = 1, no positions satisfy and .
- For i = 2, no position satisfy and .
- For i = 3, j = 1, 2 satisfy and .
- For i = 4, j = 1, 2, 3 no positions satisfy and .
Now, .
It can be seen that inversion for this array will be as:
- For i = 1, no positions satisfy and .
- For i = 2, no positions satisfy and .
- For i = 3, no positions satisfy and .
- For i = 4, j = 3 satisfy and .
Thus, is a valid permutation.
Bitwise AND sumBitwise AND sum Solution(C++):-
Similar posts:-
- C-programming MCQs part-1
- C-programming MCQs part-2
- C-programming MCQs part-3
- C-programming MCQs part-4
- C-programming MCQs part-5
- C-programming MCQs part-6
- COA MCQs part-1
- COA MCQs part-2
- COA MCQs part-3
- COA MCQs part-4
- Microprocessor 8085 MCQs part-1
- Microprocessor 8085 MCQs part-2
- Microprocessor 8085 MCQs part-3
- CSS MCQs part-1
- CSS MCQs part-2
- CSS MCQs part-3
- CSS MCQs part-4
- CSS MCQs part-5
- Engineering Mathematics -II MCQs part-1
- Engineering Mathematics -II MCQs part-2
- Engineering Mathematics -II MCQs part-3
- Engineering Mathematics -II MCQs part-4
- Engineering Mathematics -II MCQs part-5
- Operating system MCQs part-1
- Operating system MCQs part-2
- Operating system MCQs part-3
- Operating system MCQs part-4
- Operating system MCQs part-5
0 Comments