Mind the Gap

A. Mind the Gap
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

The first line of input contains two integers nn and ss (1n1001≤n≤1001s601≤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 (0h230≤h≤230m590≤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.

Output

Print two integers hh and mm — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.

Examples
input
Copy
6 60
0 0
1 20
3 21
5 0
19 30
23 40
output
Copy
6 1
input
Copy
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
output
Copy
24 50
input
Copy
3 17
0 30
1 0
12 0
output
Copy
0 0
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 2424 hours to insert the takeoff.

In the third example Arkady can insert the takeoff even between the first landing.


The meaning of the question: Find a time that can spare s minutes before and after. I wrote it for too long. I searched and found that I can do this: directly enumerate the time.

#include<iostream>  
#include<string.h>  
#include<algorithm>  
#include<cmath>  
#include<map>  
#include<string>  
#include<stdio.h>  
#include<vector>  
#include<stack>
#include<set>
using namespace std;
#define INIT ios::sync_with_stdio(false)
#define LL long long int
struct node {
	int h, m;
};

bool cmp(node s, node t) {
	if (s.h != t.h)
		return s.h < t.h;
	return s.m < t.m;
}

int main() {
	INIT;
	int n, s;
	int a, b;
	int num[10005];
	while(cin >> n >> s) {
		for (int i = 0;i < n;i++) {
			cin >> a >> b;
			num[i] = a * 60 + b;
		}
		
		for (int i = 0;i < 10000;i++) {
			int flag = 0;
			for (int j = 0;j < n;j++) {
				if (abs(num[j] - i) <= s)flag = 1;
			}
			if (!flag) {
				cout << i / 60 << ' ' << i % 60 << endl;
				break;
			}
		}

	}
	return 0;
}


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325726813&siteId=291194637