아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Security Check

시간 제한1초메모리 제한512 MB

요약
두 줄에 각각 n명이 서 있고 한 분에 한 명씩 또는 양쪽에서 한 명씩 동시에 검사할 수 있을 때, 순위 차가 k 이하인 두 사람이 동시에 검사되지 않도록 하는 최소 시간을 구한다.
난이도

보통10점 중 7점

유형
동적 계획법, 투 포인터
정답자
아직 제출이 없습니다

문제

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 AA and BB are going to travel by plane. Each team has nn players, ranked from 11 to nn according to their average performance. No two players in the same team share the same rank. Team AA is waiting in queue 11 while team BB is waiting in queue 22. 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 A_iA\_i and B_jB\_j are being checked at the same time, and their ranks are almost the same, specifically ∣A_i−B_j∣≤k|A\_i - B\_j| \leq k, 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 nn and kk: the number of players in each team and the rank similarity parameter (1≤n≤6⋅1041 \leq n \leq 6 \cdot 10^4, 1≤k≤101 \leq k \leq 10).

The second line contains nn distinct integers A_1,A_2,…,A_nA\_1, A\_2, \ldots, A\_n: the first queue from front to rear (1≤A_i≤n1 \leq A\_i \leq n).

The third line contains nn distinct integers B_1,B_2,…,B_nB\_1, B\_2, \ldots, B\_n: the second queue from front to rear (1≤B_i≤n1 \leq B\_i \leq n).

출력

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 A_1A\_1.

Minute 2: check A_2A\_2.

Minute 3: check A_3A\_3.

Minute 4: check A_4A\_4 and B_1B\_1.

Minute 5: check B_2B\_2.

Minute 6: check B_3B\_3.

Minute 7: check B_4B\_4.

예제1

  1. 예제 1

    입력
    4 2
    2 3 1 4
    1 2 4 3
    
    예상 출력
    7