GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Monday 23 May 2022

[Solution] Double Sort Codeforces Solution | Codeforces Problem Solution 2022

C. Double Sort
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given two arrays a and b, both consisting of n integers.

In one move, you can choose two indices i and j (1i,jnij) and swap ai with aj and bi with bj. You have to perform the swap in both arrays.

Solution Click Below:-  CLICK HERE

You are allowed to perform at most 104 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.

Input

The first line contains a single integer t (1t100) — the number of testcases.

The first line of each testcase contains a single integer n (2n100) — the number of elements in both arrays.

The second line contains n integers a1,a2,,an (1ain) — the first array.

The third line contains n integers b1,b2,,bn (1bin) — the second array.

Output

For each testcase, print the answer. If it's impossible to make both arrays sorted in a non-decreasing order in at most 104 moves, print -1. Otherwise, first, print the number of moves k (0k104). Then print i and j for each move (1i,jnij).

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