967A 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 ssminutes 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.


题意:呀,今天早上起来一看,题意变得清晰明了了,昨晚比赛的时候,这题是真的难读,还没有数据范围,我读了一个小时,然后加样例推样例才明白的,群里很多人都卡题意,一些手速大佬过了以后,发现一大堆人在那里Hack,明显就是有一个人过了a,锁住题,连叉8个人,恐怖,成功一个100分,800分啊,群里的大佬们反应的是应有具有。。这次a应该被叉的最惨一次,一些人庆幸没有做,还有一些人被hcak惨了的。言归正传,你是飞机场管理员,你有一张飞机降落的时间表,每个时间短就有一架飞机降落,让你最早在插入一架飞机,让飞机起飞,输出这个起飞时间,按照小时,分钟输出。为了安全考虑,你插入的飞机时间,和相邻降落的飞机时间差应该小于d,给出对的时间是小时和分钟。输入n和s,代表n个飞机降落的时间,s表示最小允许的时间间隔,比如你插入起飞 的时间和那些降落的飞机时间间隔不能少于s。输出插入飞机最早的起飞时间。

题解:模拟  分类    我们把插入飞机起飞的时间分为三种,第一种:一开始就能起飞,(在第一架飞机降落之前起飞),只需要判断s是否<第一架飞机降落的时间,第二种:插入 的起飞飞机在两个降落飞机之间,所以起飞时间和前面降落的时间只差大于s,并且和后面的降落飞机时间之差大于s。第三种:前面所有发情况都不满足,只能等所有飞机降落后,才能起飞,直接在最后一架飞机的时间上加上s+1,就是起飞时间。

#include<bits/stdc++.h>
using namespace std;
int n,d,a[100010],b[100010],sum[100010];
int main()
{
    cin>>n>>d;
    for(int i=0; i<n; i++)
        cin>>a[i]>>b[i],sum[i]=a[i]*60+b[i];
    if(d<sum[0])
        cout<<0<<" "<<0;
    else
    {
        for(int i=1; i<n; i++)
        {
            if(d*2+1<sum[i]-sum[i-1])
            {
                sum[i-1]+=d+1;
                cout<<sum[i-1]/60<<" "<<sum[i-1]%60;
                return 0;
            }
        }
        sum[n-1]+=d+1;
        cout<<sum[n-1]/60<<" "<<sum[n-1]%60;
    }
    return 0;
}


猜你喜欢

转载自blog.csdn.net/memory_qianxiao/article/details/80148606
GAP
GAP