#K2576. Train Schedule Clash Checker
Train Schedule Clash Checker
Train Schedule Clash Checker
You are given the schedule of several existing trains running on a specific route along with a schedule for a new train. Each train's schedule is represented by its departure and arrival times in 24-hour format (HHMM). Your task is to determine whether the new train can travel on the route without clashing with any of the existing train schedules.
Clash Condition: A clash occurs if the time interval of the new train intersects with any of the existing train intervals. Formally, let an existing train have an interval \([d, a]\) and the new train have the interval \([D, A]\). A clash is avoided if and only if \(A \le d\) or \(D \ge a\). Otherwise, a clash occurs.
For each test case, output "yes" if the new train schedule does not clash with any existing train schedules; otherwise, output "no".
inputFormat
The input begins with a single integer \(T\) denoting the number of test cases. Each test case is described as follows:
- An integer \(N\) representing the number of existing trains.
- \(N\) pairs of integers, where each pair represents the departure and arrival times of an existing train (in HHMM format).
- Two integers representing the departure and arrival times of the new train.
All values for a test case are provided on one line separated by spaces.
outputFormat
For each test case, output a single line containing "yes" if the new train schedule does not clash with any of the existing schedules, or "no" if there is a clash.
## sample3
4 1500 1600 900 1000 1130 1230 1630 1730 1100 1200
0 1100 1200
2 1000 1030 1100 1130 1030 1100
no
yes
yes
</p>