#P13609. [NWRRC 2022] Limited Swaps
[NWRRC 2022] Limited Swaps
题目描述
Lina is playing with cubes placed in a row. Each cube has an integer from to written on it. Every integer from to appears on exactly one cube.
Initially, the numbers on the cubes from left to right are . Lina wants the numbers on the cubes from left to right to be .
Lina can swap any two adjacent cubes, but only if the difference between the numbers on them is at least . This operation can be performed at most times.
Find any sequence of swaps that transforms the initial configuration of numbers on the cubes into the desired one, or report that it is impossible.
输入格式
The first line contains a single integer --- the number of cubes ().
The second line contains distinct integers --- the initial numbers on the cubes from left to right ().
The third line contains distinct integers --- the desired numbers on the cubes from left to right ().
输出格式
If it is impossible to obtain the desired configuration of numbers on the cubes from the initial one, print a single integer .
Otherwise, in the first line, print a single integer --- the number of swaps in your sequence ().
In the second line, print integers describing the operations in order (). Integer stands for "swap the -th cube from the left with the -th cube from the left".
You do not have to find the shortest solution. Any solution satisfying the constraints will be accepted.
5
1 3 5 2 4
3 5 1 4 2
3
1 2 4
4
1 2 3 4
4 3 2 1
-1
提示
In the first example test, the configuration of numbers changes as follows:
In the second example test, making even a single swap in the initial configuration is impossible.