An aquarium's tanks are numbered consecutively along a corridor. The facility has installed n motion sensors; sensor i continuously monitors every tank number from start_i to end_i, inclusive. A safety inspector wants to confirm that a specific inspection interval — every tank number from left to right, inclusive — is fully covered, meaning every single tank number in [left, right] is monitored by at least one of the n sensors (a tank may be covered by more than one sensor, or by none at all).
Given the sensors' ranges and the inspection interval, determine whether the interval is fully covered.
The first line contains three integers n, left, and right. Each of the next n lines contains two integers start_i and end_i, describing one sensor's monitored range (with start_i <= end_i).
Print a single line containing exactly true if every integer in [left, right] is covered by at least one sensor's range, or false otherwise.
Example 1
Input
2 10 15 8 12 13 18
Expected
true
Explanation
Sensor 1 covers tanks 8 through 12, and sensor 2 covers tanks 13 through 18. Together they cover 10, 11, 12 (sensor 1) and 13, 14, 15 (sensor 2), so every tank from 10 to 15 is covered: true.
Example 2
Input
2 5 9 1 4 6 10
Expected
false
Explanation
Sensor 1 covers up to tank 4, and sensor 2 starts at tank 6, so tank 5 is covered by neither sensor: false.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →