967A.md (2087B)
1 Source: https://codeforces.com/problemset/problem/967/A 2 3 A. Mind the Gap 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $1$ minute. 22 23 He was asked to insert one takeoff in the schedule. The takeoff takes $1$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $s$ minutes from both sides. 24 25 Find the earliest time when Arkady can insert the takeoff. 26 27 Input 28 29 The first line of input contains two integers $n$ and $s$ ($1 \le n \le 100$, $1 \le s \le 60$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. 30 31 Each of next $n$ lines contains two integers $h$ and $m$ ($0 \le h \le 23$, $0 \le m \le 59$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $0$ $0$). These times are given in increasing order. 32 33 Output 34 35 Print two integers $h$ and $m$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. 36 37 Examples 38 39 Input 40 41 ``` 42 6 60 43 0 0 44 1 20 45 3 21 46 5 0 47 19 30 48 23 40 49 ``` 50 51 Output 52 53 ``` 54 6 1 55 ``` 56 57 Input 58 59 ``` 60 16 50 61 0 30 62 1 20 63 3 0 64 4 30 65 6 10 66 7 50 67 9 30 68 11 10 69 12 50 70 14 30 71 16 10 72 17 50 73 19 30 74 21 10 75 22 50 76 23 59 77 ``` 78 79 Output 80 81 ``` 82 24 50 83 ``` 84 85 Input 86 87 ``` 88 3 17 89 0 30 90 1 0 91 12 0 92 ``` 93 94 Output 95 96 ``` 97 0 0 98 ``` 99 100 Note 101 102 In the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute. 103 104 In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $24$ hours to insert the takeoff. 105 106 In the third example Arkady can insert the takeoff even between the first landing.