Security Check
시간 제한1초메모리 제한512 MB
두 줄에 각각 n명이 서 있고 한 분에 한 명씩 또는 양쪽에서 한 명씩 동시에 검사할 수 있을 때, 순위 차가 k 이하인 두 사람이 동시에 검사되지 않도록 하는 최소 시간을 구한다.
문제
In the airport of Bytetown, there are two long queues waiting for the security check. Checking a person takes one minute, and the two queues can be checked at the same time.
Two teams and are going to travel by plane. Each team has players, ranked from to according to their average performance. No two players in the same team share the same rank. Team is waiting in queue while team is waiting in queue . Nobody else is waiting for the security check.
Little Q is the policeman who manages two queues. Every minute, he can either check the first person from one of the queues, or check the first persons from both queues at the same time. He can't change the order in the queues because that will make people unhappy. There is an additional complication, however: if two players and are being checked at the same time, and their ranks are almost the same, specifically , they will make a lot of noise. Little Q should never let that happen.
Please write a program to help Little Q find a way to check all the people so that the required time is minimum possible.
입력
The first line of the input contains two integers and : the number of players in each team and the rank similarity parameter (, ).
The second line contains distinct integers : the first queue from front to rear ().
The third line contains distinct integers : the second queue from front to rear ().
출력
Print a single line containing a single integer: the minimum time required to check all the people.
힌트
One possible solution is as follows.
Minute 1: check .
Minute 2: check .
Minute 3: check .
Minute 4: check and .
Minute 5: check .
Minute 6: check .
Minute 7: check .