欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF967A.Mind the Gap
Mind the Gap
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 minute.
He was asked to insert one takeoff in the schedule. The takeoff takes minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least minutes from both sides.
Find the earliest time when Arkady can insert the takeoff.
Input
The first line of input contains two integers and (, ) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff.
Each of next lines contains two integers and (, ) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is ). These times are given in increasing order.
Output
Print two integers and — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
Note
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.
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 hours to insert the takeoff.
In the third example Arkady can insert the takeoff even between the first landing.
Samples
6 60
0 0
1 20
3 21
5 0
19 30
23 40
6 1
16 50
0 30
1 20
3 0
4 30
6 10
7 50
9 30
11 10
12 50
14 30
16 10
17 50
19 30
21 10
22 50
23 59
24 50
3 17
0 30
1 0
12 0
0 0
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |