[Solution] Double Sort Codeforces Solution | Codeforces Problem Solution 2022
You are given two arrays and , both consisting of integers.
In one move, you can choose two indices and (; ) and swap with and with . You have to perform the swap in both arrays.
You are allowed to perform at most moves (possibly, zero). Can you make both arrays sorted in a non-decreasing order at the end? If you can, print any sequence of moves that makes both arrays sorted.
The first line contains a single integer () — the number of testcases.
The first line of each testcase contains a single integer () — the number of elements in both arrays.
The second line contains integers () — the first array.
The third line contains integers () — the second array.
For each testcase, print the answer. If it's impossible to make both arrays sorted in a non-decreasing order in at most moves, print -1. Otherwise, first, print the number of moves . Then print and for each move ; .
If there are multiple answers, then print any of them. You don't have to minimize the number of moves.
No comments:
Post a Comment