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

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

Hectic Harbour

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

요약
길이 n인 레일 위 두 크레인이 서로 교차하지 않으면서 주어진 순서대로 작업 위치를 방문할 때, 둘 다 작업을 마치는 최소 시간을 구한다.
난이도

보통10점 중 7점

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

문제

There are two gantry cranes operating on the same gantry of length nn. The gantry has some fixed integral positions, labelled from 11 to nn, at which the cranes must perform loading/unloading operations. In the beginning the first gantry crane is located on the very left of the gantry at position 11, while the second one is located on the very right of the gantry at position nn. In each time step a gantry crane can either move to a neighbouring integral position or stay at its current position (and potentially perform a loading/unloading operation). To prevent the gantry cranes from hitting each other, the first crane needs to stay strictly to the left of the second crane at all times. For both cranes you are given a task list consisting of gantry positions at which the cranes must perform loading/unloading operations. Both cranes must perform their assigned operations in the given order. What is the minimal amount of time necessary for both gantry cranes to finish their tasks? It is guaranteed that the first gantry crane never has to operate at position nn of the gantry while the second gantry crane never has to operate at position 11. For both gantry cranes the first and last loading/unloading operation in the task list is their initial position.

입력

The input consists of:

  • One line with integers nn, aa and bb where
  • nn (2≤n≤2,0002 \le n \le 2\\,000) is the length of the gantry;
  • aa (2≤a≤502 \le a \le 50) is the number of operations in the task list of the first gantry crane;
  • bb (2≤b≤502 \le b \le 50) is the number of operations in the task list of the second gantry crane. 
  • One line with aa integers k_1,…,k_ak\_1, \ldots, k\_a (1≤k_i≤n−11 \le k\_i \le n-1 for all ii), the tasks of the first gantry crane. 
  • One line with bb integers ℓ_1,…,ℓ_b\ell\_1, \ldots, \ell\_b (2≤ℓ_i≤n2 \le \ell\_i \le n for all ii), the tasks of the second gantry crane. 

The first and last task of both gantry cranes are at their initial position, i.e., k_1=k_a=1k\_1 = k\_a = 1 and ℓ_1=ℓ_b=n\ell\_1 = \ell\_b = n.

출력

Output the minimum number of time steps necessary for both gantry cranes to finish their assigned tasks.

힌트

In the first sample test case the gantry is of length 3, the first gantry crane has 2 operations in its task list while the second gantry crane has 4 operations in its task list. At least 6 time steps are necessary for both gantry cranes to finish their assigned tasks.

TimeGantry Crane 1Gantry Crane 2
1Operate at 1Operate at 3
2Operate at 1Operate at 3
3Idle at 1Move from 3 to 2
4Idle at 1Operate at 2
5Idle at 1Move from 2 to 3
6Idle at 1Operate at 3

In the second sample test case the gantry is of length 4 and both gantry cranes have to perform 4 operations. At least 9 time steps are necessary for both gantry cranes to finish their assigned tasks.

TimeGantry Crane 1Gantry Crane 2
1Operate at 1Operate at 4
2Move from 1 to 2Move from 4 to 3
3Operate at 2Operate at 3
4Move from 2 to 3Move from 3 to 4
5Operate at 3Idle at 4
6Move from 3 to 2Move from 4 to 3
7Move from 2 to 1& Operate at 3
8Operate at 1Move from 3 to 4
9Idle at 1Operate at 4

예제2

  1. 예제 1

    입력
    3 2 4
    1 1
    3 3 2 3
    
    예상 출력
    6
    
  2. 예제 2

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