cswork / OA打开练习工作台

MetaOA #4

Earliest Common Meeting Slot

估计中等可在线判题

考点(AI 标注)前缀和区间

A day is [0,1440) minutes. Given the busy half-open intervals of all employees, find the earliest integer start time at which all employees are free and a meeting of the given length fits; if none exists, output −1. The original site's example answer of 240 conflicts with the busy intervals, so this site corrected it to 60.

输入格式

This site combines all employees' busy intervals into one input: the first line contains the total number of intervals b (0..100000) and the meeting length L (1..1440); the next b lines are start finish (0≤start<finish≤1440). Intervals may overlap and may be unsorted.

输出格式

Output the answer as described; separate multiple results with spaces in order, and output an empty line for an empty array.

样例 1

输入:

6 120
180 240
720 900
0 60
540 600
330 360
540 600

输出:

60

样例 2

输入:

0 1440

输出:

0

样例 3

输入:

1 1
0 1440

输出:

-1

样例说明

Example 1: everyone is free during [60,180), whose length is exactly 120; before that, someone is busy during [0,60), so the earliest start time is 60.