Time Limit: 6000/3000 MS (Java/Others)

Memory Limit: 524288/524288 K (Java/Others)

In airport of Bytetown, there are two long queues waiting for security check. Checking a person needs one minute, and two queues can be checked at the same time.

Picture from Wikimedia Commons

Two teams $A$ and $B$ are going to travel by plane. Each team has $n$ players, ranked from $1$ to $n$ according to their average performance. No two players in the same team share the same rank. Team $A$ is waiting in queue $1$ while team $B$ is waiting in queue $2$. Nobody else is waiting for security check.

Little Q is the policeman who manages two queues. Every time he can check one person from one queue, or check one each person from both queues at the same time. He can't change the order of the queue, because that will make someone unhappy. Besides, if two players $A_i$ and $B_j$ are being checked at the same time, satisfying $|A_i-B_j|\leq k$, they will make a lot of noise because their rank are almost the same. Little Q should never let that happen.

Please write a program to help Little Q find the best way costing the minimum time.

Picture from Wikimedia Commons

Two teams $A$ and $B$ are going to travel by plane. Each team has $n$ players, ranked from $1$ to $n$ according to their average performance. No two players in the same team share the same rank. Team $A$ is waiting in queue $1$ while team $B$ is waiting in queue $2$. Nobody else is waiting for security check.

Little Q is the policeman who manages two queues. Every time he can check one person from one queue, or check one each person from both queues at the same time. He can't change the order of the queue, because that will make someone unhappy. Besides, if two players $A_i$ and $B_j$ are being checked at the same time, satisfying $|A_i-B_j|\leq k$, they will make a lot of noise because their rank are almost the same. Little Q should never let that happen.

Please write a program to help Little Q find the best way costing the minimum time.

The first line of the input contains an integer $T(1\leq T\leq15)$, denoting the number of test cases.

In each test case, there are $2$ integers $n,k(1\leq n\leq 60000,1\leq k\leq 10)$ in the first line, denoting the number of players in a team and the parameter $k$.

In the next line, there are $n$ distinct integers $A_1,A_2,...,A_n(1\leq A_i\leq n)$, denoting the queue $1$ from front to rear.

Then in the next line, there are $n$ distinct integers $B_1,B_2,...,B_n(1\leq B_i\leq n)$, denoting the queue $2$ from front to rear.

In each test case, there are $2$ integers $n,k(1\leq n\leq 60000,1\leq k\leq 10)$ in the first line, denoting the number of players in a team and the parameter $k$.

In the next line, there are $n$ distinct integers $A_1,A_2,...,A_n(1\leq A_i\leq n)$, denoting the queue $1$ from front to rear.

Then in the next line, there are $n$ distinct integers $B_1,B_2,...,B_n(1\leq B_i\leq n)$, denoting the queue $2$ from front to rear.

For each test case, print a single line containing an integer, denoting the minimum time to check all people.

提交代码