#K33457. Find Best Start Time for Minimum Travel Time
Find Best Start Time for Minimum Travel Time
Find Best Start Time for Minimum Travel Time
Given a journey of a certain distance and varying traffic conditions, your task is to determine the optimal start time that minimizes the travel time. The travel time is calculated using the formula (\text{Travel Time} = \frac{\text{Distance}}{\text{Speed}}). Only consider time slots with a speed greater than 0 to avoid division by zero. If the distance is 0, the travel time is 0 regardless of the traffic conditions. In case multiple time slots produce the same travel time, choose the earliest hour.
inputFormat
The first line contains an integer (D) representing the distance in kilometers. The second line contains an integer (N) representing the number of time entries. Each of the following (N) lines contains two space-separated integers (H) and (S), where (H) (0 (\leq H \leq) 23) is the hour of the day and (S) is the average speed in km/h during that hour.
outputFormat
Output a single line in the format: "The best start time is at (H:00) with a travel time of (T) hours", where (H) is the optimal starting hour and (T) is the travel time rounded to at most two decimal places.## sample
120
24
0 50
1 52
2 48
3 55
4 60
5 58
6 70
7 45
8 40
9 65
10 68
11 75
12 72
13 60
14 55
15 50
16 48
17 45
18 40
19 55
20 60
21 62
22 40
23 45
The best start time is at 11:00 with a travel time of 1.6 hours