#P4594. [COCI 2011/2012 #5] BLOKOVI
[COCI 2011/2012 #5] BLOKOVI
Description
In the 2D Cartesian coordinate system, there are rectangles with masses , width , and height , such that:
- The sides of each rectangle are parallel to the coordinate axes.
- The bottom side of each rectangle does not lie on the -axis, and its -coordinate is one of the following values: .
- The lowest rectangle has its lower-left corner at , and its lower-right corner coincides with the origin.

Define the -center of a rectangle as the -coordinate of the midpoint of its bottom side. The -center of one or more rectangles is the weighted average of their -centers, computed as:
$$Xbarycetre=\frac{\sum_{i}m_{i}\times Xcentre(i)}{\sum_{i}m_{i}}$$Here, Xbarycetre denotes the -center of one or more rectangles, and Xcentre denotes the -center of a rectangle.
In other words, it is the sum of (each rectangle’s mass times its -center) divided by the total mass of the rectangles.
For each rectangle, if the distance between the -center of the rectangles above it and its own -center is at most , then the arrangement formed by these rectangles is called stable.
For example, the arrangement in the left picture is unstable because the distance between the -center of the top two rectangles and the -center of the rectangle below them is greater than . The arrangement in the right picture is stable.
Given the masses of all rectangles, find the maximum possible -coordinate of the rectangles in a stable arrangement.
You are not allowed to change the order of the rectangles; they are given from bottom to top.
Input Format
The first line contains an integer , the number of rectangles.
The next lines each contain an integer , the mass of the -th rectangle.
Output Format
Print one real number, the answer. Any answer within an error of will be accepted.
2
1
1
1.00000000
3
1
1
1
1.50000000
3
1
1
9
1.90000000
Hint
For of the testdata, the rectangle masses are given in decreasing order.
Constraints: , .
Translated from COCI 2011/2012 #5 T5.
Translated by ChatGPT 5
京公网安备 11011102002149号