Limited Swaps
시간 제한2초메모리 제한1024 MB
이웃한 두 수의 차가 2 이상일 때만 교환할 수 있을 때, 최대 20000번의 교환으로 처음 배열을 목표 배열로 바꾸거나 불가능을 판정한다.
문제
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.
힌트
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.