#P8424. [JOI Open 2022] 跷跷板 / Seesaw
[JOI Open 2022] 跷跷板 / Seesaw
Background
Translated from JOI Open 2022 T1. シーソー / Seesaw.
Problem Description
A straight rod of length is placed horizontally from left to right. You may ignore the weight of the rod. There are weights hanging on the rod, each with unit mass. The positions of these weights are all distinct. The position of the -th weight () is . That is, the distance from the left end of the rod to the -th weight is .
At the beginning, we have a box of width . We can place the rod on the box so that the box supports the part of the rod from to (), inclusive of both ends; that is, the interval on the rod from position to position . Here we must have . After that, we are not allowed to change the values of and .
Next, we remove the leftmost or the rightmost weight hanging on the rod. We need to repeat this operation times. During this process, including the initial state and the final state, the center of mass of all weights hanging on the rod must always stay between and , inclusive. If there are weights on the rod at positions , then the center of mass is at .
Given and the positions of the weights, write a program to compute the minimum possible width of the box.
Input Format
The first line contains a positive integer .
The second line contains non-negative integers .
Output Format
Output the minimum possible width of the box. Your program will be judged correct if the absolute error or relative error between your output and the standard answer is at most .
3
1 2 4
0.8333333333
6
1 2 5 6 8 9
1.166666667
Hint
[Sample Explanation #1]
The width of the box can be . Let . Do the following operations:
- Initially, the center of mass is at .
- In the first operation, we remove the rightmost weight (the weight at position ). The center of mass becomes .
- In the second operation, we remove the leftmost weight (the weight at position ). The center of mass becomes .
During this process, the center of mass always stays within the range from to .
Since the width of the box cannot be less than , output the decimal form of .
This sample satisfies the constraints of all subtasks.
[Sample Explanation #2]
This sample satisfies the constraints of all subtasks.
[Constraints]
This problem uses bundled testdata.
- Subtask 1 (1 point): .
- Subtask 2 (33 points): .
- Subtask 3 (33 points): .
- Subtask 4 (33 points): no additional constraints.
For all testdata, , .
Translated by ChatGPT 5