#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 Bita-radish seedlings. These seedlings are numbered from to , and Bitaro plans to grow them in this order. The size of the -th seedling () is . Bitaro wants every seedling to receive enough sunlight, so the seedling sizes satisfy the following conditions:
- .
- $A_{N+1} \geq A_{N+2} \geq \cdots \geq A_{2N-1} \geq A_{2N} \geq A_1$.
Note that seedling is the smallest, and seedling is the largest.
Bitaro has also prepared red pots and blue pots, and each pot also has a size. The size of the -th () red pot is , and the size of the -th () blue pot is . Bitaro plants one Bita-radish seedling in each of these pots, and arranges the pots in some order, so that seedlings are put into the pots in the order .
For appearance, these pots must be arranged in an aesthetic order. Here, an aesthetic order means that in the arrangement there exist consecutive pots of the same color. More precisely, an arrangement of pots is called aesthetic if and only if there exists an integer with such that the pots containing seedlings are all of the same color.
When a seedling of size is planted in a pot of size , the cultivation difficulty of this pair is the absolute value . Bitaro's workload for growing Bita-radish is the maximum cultivation difficulty among the 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:
- ...
- ...
- ...
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 by planting the seedlings as follows:
- Plant seedling in the first red pot. The cultivation difficulty of this pair is .
- Plant seedling in the second blue pot. The cultivation difficulty of this pair is .
- Plant seedling in the first blue pot. The cultivation difficulty of this pair is .
- Plant seedling in the second red pot. The cultivation difficulty of this pair is .
The pots containing seedlings and 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 . Therefore, the output is .
This sample input satisfies the constraints of all subtasks.
Sample Explanation 2
This sample input satisfies the constraints of subtasks .
Sample Explanation 3
This sample input satisfies the constraints of subtasks .
Constraints
- .
- ().
- ().
- ().
- .
- $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
- (4 points) .
- (5 points) .
- (21 points) .
- (37 points) All values are distinct. In addition, holds.
- (33 points) No additional constraints.
Translated by ChatGPT 5