#K95987. Scheduling Events Without Overlap

    ID: 38985 Type: Default 1000ms 256MiB

Scheduling Events Without Overlap

Scheduling Events Without Overlap

You are given multiple test cases. In each test case, you are provided with a number of events. Each event is defined by a start time \(S_i\) and an end time \(E_i\) (with \(S_i < E_i\)). Your task is to determine whether these events can be scheduled sequentially without any overlapping.

An event \(j\) overlaps with another event \(i\) if \(S_j < E_i\). In other words, after sorting the events by their start times, every event should start at or after the end time of the previous event.

If the events do not overlap, output YES. Otherwise, output NO.

Note: If there are no events in a test case, consider it as a valid schedule (output YES).

inputFormat

The input consists of multiple test cases. The first line contains an integer T, the number of test cases. For each test case:

  • The first line contains an integer N, the number of events.
  • The next N lines each contain two integers S and E separated by a space, representing the start and end times of an event.

All input is provided via standard input.

outputFormat

For each test case, output a single line containing either YES if the events can be scheduled without overlapping, or NO otherwise. The output should be printed to standard output.

## sample
2
3
1 3
2 5
6 7
2
1 2
3 4
NO

YES

</p>