#BS0000372. Hiệu chỉnh đồng hồ tốc độ (Need for Speed)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Hiệu chỉnh đồng hồ tốc độ (Need for Speed)
Need for Speed
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
Sheila's car has a miscalibrated speedometer. A reading of corresponds to a true speed of , where the unknown constant may be negative.
Her recorded journey consists of segments. On segment , the car travels miles while the speedometer continuously displays miles per hour. The entire journey lasts hours. A displayed speed may be negative, but the actual speed is strictly positive on every segment.
Determine the speedometer offset from the recorded data.
Input
The first line contains two integers , the number of segments and total duration in hours.
Each of the following lines contains two integers , the distance in miles and the displayed speed in miles per hour on segment .
Output
Print one real number in miles per hour. For submitted value and correct value , acceptance requires .
Subtasks
- Subtask 1 (20 points): ; ; , ().
- Subtask 2 (30 points): ; ; , (); .
- Subtask 3 (50 points): ; ; , ().
Examples
Input
3 5
4 -1
4 0
10 3
Output
3.000000000
Explanation
For , the actual speeds are . The travel times are , , and hours, summing to . All speeds are positive. Since the total time strictly decreases with , this is the unique solution.
Input
1 4
8 5
Output
-3.000000000
Explanation
The true speed is miles per hour. The reading is , so .
Input
2 3
3 2
6 2
Output
1.000000000
Explanation
Both readings are . Total distance is miles in hours, so the true speed is and the offset is .
Input
4 10
5 3
2 2
3 6
3 1
Output
-0.508653377
Explanation
For , the four true speeds are approximately , , and miles per hour, all positive. Total time $5/2.491346623+2/1.491346623+3/5.491346623+3/0.491346623$ is approximately 10 hours. Total time strictly decreases as increases, so this identifies the unique root within the permitted error.