| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 4 초 | 2048 MB | 4 | 2 | 1 | 100.000% |
Annual Egg Drop Challenge is about to start! There are $n$ people participating in the challenge. They are standing on different floors of the same building, and the $i$-th of them stands on the $i$-th floor, at a height of $h_i$ above the ground. The person on the $n$-th floor is holding an egg. The task of the participants is to safely lower this egg to the first floor as quickly as possible.
When person $i$ holds an egg in their hands, they can throw it down with any real-valued speed from 0ドル$ to $v_i$.
When the egg flies past person $i,ドル that is, when it is at a height of $h_i,ドル they can (but are not obliged to) catch it if it flies at a speed of at most $u_i$. Catching the egg means completely stopping it. The egg is considered to be safely lowered to the first floor when it was caught by person 1ドル$.
When the egg is falling, it falls with the acceleration of free fall $g$. For simplicity of calculations, we will assume that there is no air resistance, and we will also assume that $g=1$. In the Note section below, you can find equations that describe the motion of the egg under such assumptions. Catching and throwing are assumed to happen instantly.
Help the participants find the shortest time possible to safely lower the egg to the first floor, or tell them that it is impossible to do so.
The first line contains a single integer $n,ドル the number of people participating in the challenge (2ドル \le n \le 3 \cdot 10^5$).
The next $n$ lines describe the people participating in the challenge. The $i$-th such line describes person $i$ and contains three integers: $h_i,ドル $v_i,ドル and $u_i$ (1ドル \le h_i \le 10^{18}$; 1ドル \le v_i, u_i \le 10^9$): the height of person $i$ above the ground and the maximum speed with which they can throw and catch an egg, respectively.
It is guaranteed that $h_i < h_{i+1}$ for all 1ドル \le i \le n - 1$.
If it is possible to lower an egg to the first floor by satisfying all the constraints, print a line with one real number: the minimum time it takes to do this. The answer will be considered correct if the absolute or relative error does not exceed 10ドル^{-6}$.
Otherwise, print a line with the number $-1$.
5 2 1 7 14 6 4 18 1 7 21 2 5 28 4 10
6.00000000000000000000
2 1 1 4 10 5 1
-1
If the egg starts flying at a speed of $v,ドル then after flying for $t$ seconds, it will move at a speed of $v + g \cdot t,ドル or just $v + t$ in our case, and will cover the total distance of $v \cdot t + g \cdot \frac{t^2}{2},ドル or just $v \cdot t + \frac{t^2}{2}$ in our case.
In the first example, the optimal solution looks as follows:
In the second example, even if person 2ドル$ throws the egg at a speed of 0ドル,ドル it will still move faster than 4ドル$ when it reaches the first floor. So, safe lowering is impossible.