No.343 手抜き工事のプロ
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
Problem Statement
You run a construction business and have been asked to check the design of, and build, a monument commemorating the $N$-th anniversary of the municipal government of Kima City.
The monument is a tower-like structure made by stacking $N$ rectangular cuboid steel pieces, each 100cm long, $L$ cm wide, and 1cm high, vertically on a horizontal base, with the width direction of each piece oriented north-south. Furthermore, the $i$-th piece from the bottom $(2 \leq i \leq N)$ is placed at a position shifted $X_i$ cm to the north relative to the position of the bottom piece (if $X_i$ is negative, it is shifted $|X_i|$ cm to the south).
To prevent collapse, the steel pieces must be welded to each other, but for technical reasons, welding cannot be done properly unless the contact area between the pieces is at least 100cm$^2$.
If this requirement is not met, you must tell the client that the design is broken.
If there is no problem with the design, you are supposed to perform welding at the $N-1$ places between the pieces (the bottom piece alone is already firmly fixed to the base, so no welding is needed between it and the base).
By the way, you are also a professional at cutting corners in construction.
You have noticed that, for each $i \ (1 \leq i \leq N-1)$, if the vertical line through the center of mass of all the steel pieces above the $i$-th piece from the bottom passes through (the interior of) both the $i$-th piece from the bottom and the $i+1$-th piece, then the monument will not immediately collapse even without welding between the $i$-th piece from the bottom and the $i+1$-th piece.
However, if the vertical line passes exactly through the surface of (at least one of) the pieces, leaving it unwelded would be unstable and it would seem ready to collapse at any moment, so welding is required.
At minimum, how many places do you need to weld so that the monument will not immediately collapse?
The steel pieces can be regarded as rigid bodies (objects that do not deform) of uniform density, and any changes in shape, mass, or density distribution due to welding can be ignored.
Also, steel pieces welded together can be regarded as one rigid body (they do not separate even if a large force is applied).
Input
$N$ $L$ $X_2$ $X_3$ $\vdots$ $X_N$
$N$, $L$, $X_i \ (2 \leq i \leq N)$ are integers, and
$1 \leq N \leq 10^5$
$1 \leq L \leq 10^4$
$|X_i| \leq 5 \times 10^3$
are satisfied.
Output
Output the number of places that need welding (-1 if the design is broken), followed by a newline.
Sample
Sample 1
Input
1 6
Output
0
(The right side is north, ■ is steel, □ is empty space)
■■■■■■
You weren't asked to do any welding in the first place...
Sample 2
Input
4 2 -1 0 1
Output
3
□□■■
□■■□
■■□□
□■■□
All 3 places require welding.
Sample 3
Input
2 4 4
Output
-1
□□□□■■■■
■■■■□□□□
The design is broken.
Sample 4
Input
3 5 -3 -1
Output
0
□□■■■■■□
■■■■■□□□
□□□■■■■■
A chance to cut corners!
Sample 5
Input
5 100 13 29 54 103
Output
0
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
FF256grhy