#C10234. Non-Overlapping Sessions

    ID: 39417 Type: Default 1000ms 256MiB

Non-Overlapping Sessions

Non-Overlapping Sessions

You are given a number of sessions. Each session has a start time and an end time. In order to attend a session, you must remain for the entire duration of that session. Your task is to determine whether it is possible to attend all sessions without any overlapping.

Formally, you are given an integer \(n\) and \(n\) sessions described by their start time and end time. Determine if there is a way to attend all sessions such that no two sessions overlap. Two sessions \((s_1, e_1)\) and \((s_2, e_2)\) are considered non-overlapping if \(s_2 \geq e_1\) when \(s_1 \leq s_2\).

Output YES if it is possible to attend all sessions, and NO otherwise.

inputFormat

Input is read from standard input (stdin) and has the following format:

n
s1 e1
s2 e2
... 
sn en

Where n is the number of sessions, and each of the following n lines contains two integers representing the start time and end time of a session respectively.

outputFormat

Output a single line to standard output (stdout) containing either YES if it is possible to attend all sessions without any overlap, or NO otherwise.

## sample
2
5 8
1 5
YES