#P10435. [JOIST 2024] 有趣的家庭菜园 5 / Growing Vegetables is Fun 5

[JOIST 2024] 有趣的家庭菜园 5 / Growing Vegetables is Fun 5

Problem Description

Bitaro, who has been passionate about gardening for many years, plans to start growing a plant called Bita-radish from this spring.

Bitaro has prepared 2N2N Bita-radish seedlings. These seedlings are numbered from 11 to 2N2N, and Bitaro plans to grow them in this order. The size of the ii-th seedling (1i2N1 \leq i \leq 2N) is AiA_i. Bitaro wants every seedling to receive enough sunlight, so the seedling sizes satisfy the following conditions:

  • A1A2ANAN+1A_1 \leq A_2 \leq \cdots \leq A_N \leq A_{N+1}.
  • $A_{N+1} \geq A_{N+2} \geq \cdots \geq A_{2N-1} \geq A_{2N} \geq A_1$.

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

Bitaro has also prepared NN red pots and NN blue pots, and each pot also has a size. The size of the jj-th (1jN1 \leq j \leq N) red pot is BjB_j, and the size of the kk-th (1kN1 \leq k \leq N) blue pot is CkC_k. Bitaro plants one Bita-radish seedling in each of these 2N2N pots, and arranges the pots in some order, so that seedlings are put into the pots in the order 1,2,,2N1,2,\ldots,2N.

For appearance, these 2N2N pots must be arranged in an aesthetic order. Here, an aesthetic order means that in the arrangement there exist NN consecutive pots of the same color. More precisely, an arrangement of pots is called aesthetic if and only if there exists an integer ll with 1lN+11 \leq l \leq N+1 such that the pots containing seedlings l,l+1,,l+N1l, l+1, \ldots, l+N-1 are all of the same color.

When a seedling of size yy is planted in a pot of size xx, the cultivation difficulty of this pair is the absolute value xy|x-y|. Bitaro's workload for growing Bita-radish is the maximum cultivation difficulty among the 2N2N pot-seedling pairs. Write a program that, given the information about the Bita-radish seedlings and the pots, finds the minimum possible value of Bitaro's workload, under the requirement that the pots must be arranged in an aesthetic order.

Input Format

Read the following data from standard input:

  • NN
  • A1A_1 A2A_2 ... A2NA_{2N}
  • B1B_1 B2B_2 ... BNB_N
  • C1C_1 C2C_2 ... CNC_N

Output Format

Output one value: the minimum possible value of Bitaro's workload when planting the seedlings so that the pots are arranged in an aesthetic order.

2
1 2 6 3
2 5
4 3
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
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

Hint

Sample Explanation 1

In this sample input, Bitaro can achieve a workload of 22 by planting the seedlings as follows:

  • Plant seedling 11 in the first red pot. The cultivation difficulty of this pair is 21=1|2 - 1| = 1.
  • Plant seedling 22 in the second blue pot. The cultivation difficulty of this pair is 32=1|3 - 2| = 1.
  • Plant seedling 33 in the first blue pot. The cultivation difficulty of this pair is 46=2|4 - 6| = 2.
  • Plant seedling 44 in the second red pot. The cultivation difficulty of this pair is 53=2|5 - 3| = 2.

The pots containing seedlings 22 and 33 are both blue, so the pots are arranged in an aesthetic order.

When planting seedlings so that the pots are arranged in an aesthetic order, it is impossible to achieve a workload smaller than 22. Therefore, the output is 22.

This sample input satisfies the constraints of all subtasks.

Sample Explanation 2

This sample input satisfies the constraints of subtasks 2,3,4,52,3,4,5.

Sample Explanation 3

This sample input satisfies the constraints of subtasks 2,3,52,3,5.

Constraints

  • 1N300,0001 \leq N \leq 300,000.
  • 1Ai1091 \leq A_i \leq 10^9 (1i2N1 \leq i \leq 2N).
  • 1Bj1091 \leq B_j \leq 10^9 (1jN1 \leq j \leq N).
  • 1Ck1091 \leq C_k \leq 10^9 (1kN1 \leq k \leq N).
  • A1A2ANAN+1A_1 \leq A_2 \leq \cdots \leq A_N \leq A_{N+1}.
  • $A_{N+1} \geq A_{N+2} \geq \cdots \geq A_{2N-1} \geq A_{2N} \geq A_1$.
  • All input values are integers.

Subtasks

  1. (4 points) N5N \leq 5.
  2. (5 points) N10N \leq 10.
  3. (21 points) N2,000N \leq 2,000.
  4. (37 points) All values AiA_i are distinct. In addition, AN<A2NA_N < A_{2N} holds.
  5. (33 points) No additional constraints.

Translated by ChatGPT 5