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 11 minute.
He was asked to insert one takeoff in the schedule. The takeoff takes 11 minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least ss minutes from both sides.
Find the earliest time when Arkady can insert the takeoff.
The first line of input contains two integers nn and ss (1≤n≤1001≤n≤100, 1≤s≤601≤s≤60) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff.
Each of next nn lines contains two integers hh and mm (0≤h≤230≤h≤23, 0≤m≤590≤m≤59) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is 00 00). These times are given in increasing order.
Print two integers hh and mm — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
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
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 2424 hours to insert the takeoff.
In the third example Arkady can insert the takeoff even between the first landing.
题目链接:http://codeforces.com/contest/967/problem/A
题意:给吹N个时间段,飞机起飞需要1min,降落需要1min,在空中Smin,找到飞机最早可以起飞的时间,不和其他时间段冲突。
#include <bits/stdc++.h>
using namespace std;
int main()
{
auto calc = [&] (int h, int m) ->int {
return h * 60 + m;
};
int n, s;
scanf("%d %d", &n, &s);
vector<int> t;
int h, m;
scanf("%d %d", &h, &m);
t.push_back(calc(h,m));
if(t.front() > s) {
return puts("0 0"), 0;
}
for(int i = 1;i < n;i ++) {
scanf("%d %d", &h, &m);
t.push_back(calc(h, m));
}
for(int i = 0;i < n - 1;i ++) {
int d = t[i+1] - t[i];
if(d >= 2 * s + 2) {
int res = t[i] + s + 1;
return !printf("%d %d\n", res / 60, res % 60);
}
}
int res = t.back() + s + 1;
printf("%d %d\n", res / 60, res % 60);
return 0;
}