#P8424. [JOI Open 2022] 跷跷板 / Seesaw

[JOI Open 2022] 跷跷板 / Seesaw

Background

Translated from JOI Open 2022 T1. シーソー / Seesaw.

Problem Description

A straight rod of length 109{10}^9 is placed horizontally from left to right. You may ignore the weight of the rod. There are NN weights hanging on the rod, each with unit mass. The positions of these NN weights are all distinct. The position of the ii-th weight (1iN1 \le i \le N) is AiA_i. That is, the distance from the left end of the rod to the ii-th weight is AiA_i.

At the beginning, we have a box of width ww. We can place the rod on the box so that the box supports the part of the rod from ll to rr (0l<r1090 \le l < r \le {10}^9), inclusive of both ends; that is, the interval on the rod from position ll to position rr. Here we must have r=l+wr = l + w. After that, we are not allowed to change the values of ll and rr.

Next, we remove the leftmost or the rightmost weight hanging on the rod. We need to repeat this operation N1N - 1 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 ll and rr, inclusive. If there are mm weights on the rod at positions b1,b2,,bmb_1, b_2, \ldots, b_m, then the center of mass is at b1+b2++bmm\frac{b_1 + b_2 + \cdots + b_m}{m}.

Given NN and the positions A1,A2,,ANA_1, A_2, \ldots, A_N of the NN weights, write a program to compute the minimum possible width ww of the box.

Input Format

The first line contains a positive integer NN.

The second line contains NN non-negative integers A1,A2,,ANA_1, A_2, \ldots, A_N.

Output Format

Output the minimum possible width ww 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 109{10}^{-9}.

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 56\frac{5}{6}. Let l=32,r=73l = \frac{3}{2}, r = \frac{7}{3}. Do the following operations:

  • Initially, the center of mass is at 73\frac{7}{3}.
  • In the first operation, we remove the rightmost weight (the weight at position 44). The center of mass becomes 32\frac{3}{2}.
  • In the second operation, we remove the leftmost weight (the weight at position 11). The center of mass becomes 22.

During this process, the center of mass always stays within the range from ll to rr.

Since the width of the box cannot be less than 56\frac{5}{6}, output the decimal form of 56\frac{5}{6}.

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): N20N \le 20.
  • Subtask 2 (33 points): N100N \le 100.
  • Subtask 3 (33 points): N2000N \le 2000.
  • Subtask 4 (33 points): no additional constraints.

For all testdata, 2N2×1052 \le N \le 2 \times 10^5, 0A1<A2<<AN1090 \le A_1 < A_2 < \cdots < A_N \le {10}^9.

Translated by ChatGPT 5