Codeforce---------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 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.
InputThe 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.OutputPrint 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

6 60
0 0
1 20
3 21
5 0
19 30
23 40
Output
6 1
Input
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
24 50
Input
3 17
0 30
1 0
12 0
Output
0 0
NoteIn 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.
An In at The SECOND, Example there IS NO the GAPS in at The Schedule, SO Arkady CAN only the Add Takeoff the After All Landings. Note that IT IS Possible that One Should the wait More Within last 2424 hours to INSERT at The Takeoff.
An In at The THIRD, Example Arkady CAN INSERT at The Takeoff the even . between the first landing
subject to the effect: the need for a difference between the first line of the input number of landing aircraft and two aircraft per aircraft s.
Each subsequent line input is time to land the aircraft, one hour before, after one minute, between landing and takeoff should interval s, the take-off and landing every minute. Output is the first time you can take off the
idea: Since the time of both minutes hours there, so take this unity in minutes, with different situations, can not look off (before the first aircraft to land at at 0:00 is there a time s + 1), and then see if I can in the middle of taking off (the two of aircraft if the time between the landing time 2 * s + 2), if the enumeration to the last airplane, not work, then, directly the last plane landed after takeoff s + 1 time.

#include <iostream>
#include <cstdio>

using namespace std;

const int N = 100 + 10;

int times[N];

int main(){
	int n, s;
	cin >> n >> s;

for (int i = 1; i <= n; i ++){
		int a, b;
		scanf("%d%d",&a, &b);
		times[i] = a * 60 + b;
	}

if (times[1] - s - 1 >= 0){
		cout << 0 << " " << 0 << endl;
		return 0;
	}

bool success = true;
	for (int i = 2; i <= n; i ++){
		if (times[i - 1] + 2 * s + 2 > times[i])  continue;
		else{
			int x = times[i - 1] + s + 1;
			printf("%d %d\n",x / 60, x % 60);
			success = false;
			break;
		} 
	}
	if (success){
		int x = times[n] + s + 1;
		printf("%d %d\n",x / 60, x % 60);
	}

return 0;
}
Published 106 original articles · won praise 67 · views 5441

Guess you like

Origin blog.csdn.net/qq_45772483/article/details/104741091