#K4791. Conference Scheduling

    ID: 28303 Type: Default 1000ms 256MiB

Conference Scheduling

Conference Scheduling

You are given ( T ) conferences. In each conference, there are several sessions, each with a start time and an end time (both given as integers). Your task is to determine whether all sessions in a given conference can be scheduled without overlapping. Two sessions are considered non-overlapping if the start time of a session is not less than the end time of the previous session when the sessions are sorted by their start times.

Formally, for each conference with ( N ) sessions where each session is represented by ( [A, B] ), the schedule is valid if after sorting sessions by ( A ), it holds that ( A_{i} \geq B_{i-1} ) for every ( 2 \leq i \leq N ).

inputFormat

The input is read from standard input (stdin). The first line contains an integer ( T ) representing the number of conferences. For each conference, the first line contains an integer ( N ) representing the number of sessions. This is followed by ( N ) lines, each containing two integers ( A ) and ( B ) (( 0 \leq A < B \leq 10^9 )) representing the start and end times of a session.

outputFormat

For each conference, output a line on standard output (stdout) containing "YES" if all the sessions of the conference can be scheduled without overlaps, and "NO" if there is any conflict.## sample

2
3
60 120
0 30
90 150
2
600 660
720 780
NO

YES

</p>