Growing Vegetables is Fun 5

시간 제한5초메모리 제한1024 MB

요약
비트닉 순서로 정렬된 2N개의 모종과 N개의 빨간 화분, N개의 파란 화분이 주어질 때, 같은 색 화분 N개가 연속하도록 배치하면서 화분과 모종 크기 차의 최댓값을 최소로 만든다.
난이도

어려움10점 중 8점

유형
이분 탐색, 그리디, 정렬, 구현
정답자
아직 제출이 없습니다

문제

Bitaro, who has been enjoying gardening for many years, is planning to grow a plant called Bita-radish starting this spring.

Bitaro has prepared 2N2N Bita-radish seedlings. The seedlings are numbered from 11 to 2N2N, and Bitaro plans to arrange them in this order for cultivation. The size of seedling ii (1≤i≤2N1 ≤ i ≤ 2N) is A_iA\_i. Bitaro wants every seedling to get enough sunlight, so the sizes of the seedlings satisfy the following conditions:

  • A_1≤A_2≤⋯≤A_N≤A_N+1A\_1 ≤ A\_2 ≤ \cdots ≤ A\_N ≤ A\_{N+1}.
  • A_N+1≥A_N+2≥⋯≥A_2N−1≥A_2N≥A_1A\_{N+1} ≥ A\_{N+2} ≥ \cdots ≥ A\_{2N-1} ≥ A\_{2N} ≥ A\_1.

Note that seedling 11 is the smallest and seedling N+1N + 1 is the largest.

Bitaro has also prepared NN red flowerpots and NN blue flowerpots, each of which also has a certain size. The size of the jj-th (1≤j≤N1 ≤ j ≤ N) red flowerpot is B_jB\_j, and the size of the kk-th (1≤k≤N1 ≤ k ≤ N) blue flowerpot is C_kC\_k. Bitaro plants one Bita-radish seedling in each of these total 2N2N flowerpots, and arranges the flowerpots in a row so that seedlings 1,2,…,2N1, 2, \dots, 2N are in this order.

Considering the appearance, the 2N2N flowerpots must be arranged in a beautiful order. Here, a beautiful order means an arrangement of flowerpots such that there exist consecutive NN flowerpots with the same color. More precisely, an arrangement of flowerpots is said to be a beautiful order if and only if there exists an integer ll between 11 and N+1N +1 inclusive such that the colors of the flowerpots planted with seedlings l,l+1,…,l+N−1l, l+1, \dots , l+N -1 are all the same.

When a seedling of size yy is planted in a flowerpot of size xx, the difficulty of cultivation for that pair is the absolute value ∣x−y∣|x−y|. Bitaro’s workload in growing Bita-radish is the maximum difficulty of cultivation among the 2N2N pairs of flowerpots and seedlings.

Write a program which, given the information about the Bita-radish seedlings and flowerpots, finds the minimum possible value of Bitaro’s workload when planting the seedlings so that the flowerpots are arranged in a beautiful order.

입력

The input is given from Standard Input in the following format:

NN

A_1A\_1 A_2A\_2 ⋯\cdots A_2NA\_{2N}

B_1B\_1 B_2B\_2 ⋯\cdots B_NB\_N

C_1C\_1 C_2C\_2 ⋯\cdots C_NC\_N

출력

Print a single value ― the minimum possible value of Bitaro’s workload when planting the seedlings so that the flowerpots are arranged in a beautiful order ― in a single line to Standard Output.

제한

  • 1≤N≤300,0001 ≤ N ≤ 300\\, 000.
  • 1≤A_i≤1091 ≤ A\_i ≤ 10^9 (1≤i≤2N1 ≤ i ≤ 2N).
  • 1≤B_j≤1091 ≤ B\_j ≤ 10^9 (1≤j≤N1 ≤ j ≤ N).
  • 1≤C_k≤1091 ≤ C\_k ≤ 10^9 (1≤k≤N1 ≤ k ≤ N).
  • A_1≤A_2≤⋯≤A_N≤A_N+1A\_1 ≤ A\_2 ≤ \cdots ≤ A\_N ≤ A\_{N+1}.
  • A_N+1≥A_N+2≥⋯≥A_2N−1≥A_2N≥A_1A\_{N+1} ≥ A\_{N+2} ≥ \cdots ≥ A\_{2N-1} ≥ A\_{2N} ≥ A\_1.
  • All input values are integers.

예제3

  1. 예제 1

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

    입력
    9
    1 2 3 4 5 6 7 8 9 18 17 16 15 14 13 12 11 10
    2 7 4 1 7 6 4 10 6
    6 8 9 3 7 1 9 5 4
    
    예상 출력
    8
    
  3. 예제 3

    입력
    7
    13 16 18 18 21 22 22 23 23 21 19 17 15 14
    14 14 20 19 22 17 25
    24 15 18 25 24 19 11
    
    예상 출력
    3