#K5306. Workshop Conflict Checker
Workshop Conflict Checker
Workshop Conflict Checker
You are given n workshops. Each workshop is scheduled for a continuous range of days from start day to end day. Mark wants to attend all workshops, but he can only do so if none of the workshop schedules conflict with each other.
Two workshops i and j are said to be in conflict if their intervals overlap, i.e. if the start day of one workshop occurs before or on the end day of the other. Formally, if the intervals are \( [S_i, E_i] \) and \( [S_j, E_j] \), then they conflict if \( S_j \le E_i \) (assuming the workshops are considered in sorted order by their start times).
Your task is to determine whether Mark can attend all workshops without any scheduling conflicts. If there is any conflict, output NO
; otherwise, output YES
.
Note: Workshops that are adjacent (i.e., one ends on day \(d\) and the next starts on day \(d+1\)) do not conflict, but if a workshop starts on the same day the previous one ends, it is considered a conflict.
inputFormat
The input is read from standard input (stdin) and is formatted as follows:
n S1 E1 S2 E2 ... Sn En
Where:
n
is an integer representing the number of workshops.- Each of the next
n
lines contains two integers:Si
(the start day) andEi
(the end day) of a workshop.
</p>
outputFormat
Output a single line to standard output (stdout):
YES
If Mark can attend all workshops without conflicts. Otherwise, output:
NO## sample
2
1 5
6 10
YES