#K75852. Find the Common Available Timeslot

    ID: 34511 Type: Default 1000ms 256MiB

Find the Common Available Timeslot

Find the Common Available Timeslot

You are given the available time windows for n employees. Each employee's availability is specified by a pair of integers representing the start time and end time. The time is measured in minutes. Your task is to determine the common available timeslot for all employees. The common timeslot is the intersection of all employees' time windows, defined as:

[ [s, e] = [\max_{1\le i \le n}(s_i),; \min_{1\le i \le n}(e_i)] ]

If \(s < e\), then the interval [s, e] is the valid common timeslot; otherwise, if no such overlapping interval exists, output -1.

Input: The first line contains an integer n representing the number of employees. The following n lines each contain two space-separated integers, the start time and the end time of an employee's availability.

Output: If a common available timeslot exists, print the start and end times separated by a space. Otherwise, print -1.

inputFormat

The input is read from standard input (stdin). It consists of:

  • An integer n representing the number of employees.
  • n subsequent lines, each containing two space-separated integers, the start time and the end time of an employee's available window.

outputFormat

Output the common available timeslot to standard output (stdout). If a valid overlapping interval exists, print the start and end times separated by a single space. Otherwise, print -1.

## sample
4
600 720
660 900
630 750
700 800
700 720