#K57892. Finding Free Time Slots in a Calendar
Finding Free Time Slots in a Calendar
Finding Free Time Slots in a Calendar
You are given a series of busy time intervals for a person's calendar and an overall time period \( [T_{start}, T_{end}] \). The busy intervals are provided as pairs of integers representing the start and end times and might be unsorted and overlapping.
Your task is to determine the free time intervals within the overall period during which the person is available. In other words, compute the intervals that are not covered by any of the busy intervals.
More formally, let the busy intervals be \( [s_i, e_i] \) for \( i = 1,2,\ldots,n \). After merging any overlapping intervals into a continuous block, output the intervals \( [a_j, b_j] \) such that:
[ \begin{aligned} & a_1 = T_{start}, \quad b_1 = \text{start of the first merged interval} \[6pt] & a_j = \text{end of the }(j-1)\text{-th merged interval}, \quad b_j = \text{start of the }j\text{-th merged interval}, \quad 2 \le j \le k \[6pt] & \text{if the end of the last merged interval} < T_{end}, \text{ then } [\text{end of the last merged interval}, T_{end}] \text{ is also free.} \end{aligned} ]
Print each free interval on a new line as two space-separated integers representing the start and end of that interval.
inputFormat
The input is read from standard input (stdin) using the following format:
- The first line contains an integer \( n \), the number of busy intervals.
- The next \( n \) lines each contain two space-separated integers representing the start time and end time of a busy interval.
- The last line contains two space-separated integers: \( T_{start} \) and \( T_{end} \), representing the overall time period.
outputFormat
Output the free time intervals to standard output (stdout). Each free interval should be printed on a new line as two space-separated integers (start and end). If there are no free intervals, do not print anything.
## sample0
0 8
0 8
</p>