#BS0000383. Bay lên qua lớp chắn (Careful Ascent)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bay lên qua lớp chắn (Careful Ascent)
Careful Ascent
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
Mal travels from to the stationary Firefly at on Zarzos. His vertical speed is fixed at 1 km/min. Before departure he sets a horizontal velocity (km/min). There are non-overlapping altitude intervals of energy shields. Shield spans altitudes to and changes the horizontal velocity to while inside; outside the shields it returns to . The vertical speed is unaffected. Determine so that Mal reaches Firefly.

Input
The first line contains integers (km). The second line contains integer . Each of the next lines contains integers (km) and real .
Output
Print the horizontal velocity in km/min. The absolute or relative error must not exceed .
Subtasks
- Subtask 1 (20 points): ; ; ; ; has at most 10 decimal places; ; for all , or .
- Subtask 2 (30 points): ; ; ; ; has at most 10 decimal places; ; for all , or .
- Subtask 3 (50 points): ; ; ; ; has at most 10 decimal places; ; for all , or .
Examples
Input
100 140
1
40 90 0.2000000000
Output
1.0
Explanation
The three intervals last 40, 50 and 50 minutes. At setting 1, their horizontal displacements are 40, 10 and 50 km, totalling 100 km.
Input
100 100
3
0 20 2.0000000000
50 100 0.1000000000
20 50 0.2000000000
Output
1.96078431373
Explanation
The three shields cover the entire altitude range. Their displacements are , and . Thus and .