#C5459. Check for Overlapping Intervals
Check for Overlapping Intervals
Check for Overlapping Intervals
You are given a list of intervals. Each interval is represented by two integers, representing its start and end. Your task is to determine if there exists at least one pair of intervals that overlap. Two intervals [a, b] and [c, d] are said to overlap if and only if b > c when sorted in increasing order of their start times. Note that touching intervals where b = c are not considered overlapping.
In formal terms, given a set of intervals \(I = \{[a_i, b_i]\}\), sort it by \(a_i\) so that \(a_1 \leq a_2 \leq \cdots \leq a_N\). Then, if there exists an index \(i\) such that \(b_i > a_{i+1}\), output YES
; otherwise, output NO
.
inputFormat
The input is read from standard input and has the following format:
N a1 b1 a2 b2 ... aN bN
Where N is the number of intervals, and each of the next N lines contains two space‐separated integers representing the start and end of an interval.
outputFormat
Print a single line to standard output: YES
if any two intervals overlap, and NO
otherwise.
3
1 5
6 10
5 6
NO