#C7851. Interval Insertion Without Overlap

    ID: 51768 Type: Default 1000ms 256MiB

Interval Insertion Without Overlap

Interval Insertion Without Overlap

You are given a list of non-overlapping intervals and a target interval. Your task is to determine whether the target interval can be added to the list without overlapping any of the existing intervals.

An interval is represented by a pair of numbers (start, end). Two intervals \([a, b]\) and \([c, d]\) are said to overlap if \(a < d\) and \(b > c\). The target interval can be inserted if it does not overlap with any of the intervals in the list.

Note: Consider the intervals to be in a continuous number line and the input values may be integers or floats.

inputFormat

The input is given via standard input (stdin) in the following format:

  1. An integer n representing the number of existing intervals.
  2. n lines follow, each line contains two numbers (start and end) separated by space representing an interval.
  3. One line with two numbers separated by space representing the target interval.

Example:

3
1 3
5 8
10 15
3 5

outputFormat

The output is a single line to standard output (stdout) containing either True or False depending on whether the target interval can be added without overlapping any existing intervals.

Example:

True
## sample
3
1 3
5 8
10 15
3 5
True