Egg Drop Challenge

시간 제한4초메모리 제한2048 MB

요약
각 층의 사람마다 던지는 속도와 받는 속도 한계가 주어질 때, n층에서 1층까지 달걀을 가장 빠르게 옮기는 시간을 구한다.
난이도

보통10점 중 7점

유형
이분 탐색, 그리디, 수학, 구현
정답자
아직 제출이 없습니다

문제

Annual Egg Drop Challenge is about to start! There are nn people participating in the challenge. They are standing on different floors of the same building, and the ii-th of them stands on the ii-th floor, at a height of h_ih\_i above the ground. The person on the nn-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 ii holds an egg in their hands, they can throw it down with any real-valued speed from 00 to v_iv\_i.

When the egg flies past person ii, that is, when it is at a height of h_ih\_i, they can (but are not obliged to) catch it if it flies at a speed of at most u_iu\_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 11.

When the egg is falling, it falls with the acceleration of free fall gg. For simplicity of calculations, we will assume that there is no air resistance, and we will also assume that g=1g=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 nn, the number of people participating in the challenge (2≤n≤3⋅1052 \le n \le 3 \cdot 10^5).

The next nn lines describe the people participating in the challenge. The ii-th such line describes person ii and contains three integers: h_ih\_i, v_iv\_i, and u_iu\_i (1≤h_i≤10181 \le h\_i \le 10^{18}; 1≤v_i,u_i≤1091 \le v\_i, u\_i \le 10^9): the height of person ii 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+1h\_i < h\_{i+1} for all 1≤i≤n−11 \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−610^{-6}.

Otherwise, print a line with the number −1-1.

힌트

If the egg starts flying at a speed of vv, then after flying for tt seconds, it will move at a speed of v+g⋅tv + g \cdot t, or just v+tv + t in our case, and will cover the total distance of v⋅t+g⋅t22v \cdot t + g \cdot \frac{t^2}{2}, or just v⋅t+t22v \cdot t + \frac{t^2}{2} in our case.

In the first example, the optimal solution looks as follows:

  • Person 55 throws the egg at a speed of 44. After flying for 22 seconds, it will cover 4⋅2+222=104 \cdot 2 + \frac{2^2}{2}=10 meters and will be moving at a speed of 66, so person 33 will be able to catch it.
  • Person 33 throws the egg at a speed of 11, and after 22 seconds, person 22 will catch it.
  • Person 22 throws the egg at a speed of 55, and after 22 more seconds, person 11 will catch it, completing the challenge in 66 seconds.

In the second example, even if person 22 throws the egg at a speed of 00, it will still move faster than 44 when it reaches the first floor. So, safe lowering is impossible.

예제2

  1. 예제 1

    입력
    5
    2 1 7
    14 6 4
    18 1 7
    21 2 5
    28 4 10
    
    예상 출력
    6.00000000000000000000
    
  2. 예제 2

    입력
    2
    1 1 4
    10 5 1
    
    예상 출력
    -1