Lecture Room Reservation System
InterviewTime limit1sMemory limit1024 MB
Given reservation requests sorted by start time, decide for each whether it overlaps an accepted booking in the same room and print YES or NO.
- Level
Easy3 of 10
- Topics
- Array, Greedy, Implementation
- Solved
- No attempts yet
Problem
Chungnam National University's Engineering Building 5 has lecture rooms numbered from to . Students reserve a room through the reservation system before using it. To reserve a room, a student sends the room number , a start time , and an end time to the system.
One day, the system receives reservation requests. The requests arrive in order of start time from earliest to latest, and no two requests share the same start time. The system checks the requests in order. If a request does not overlap any reservation already accepted for the same room, the system accepts it. Otherwise, it rejects it. Two reservations where one ends at the exact time the other starts do not overlap.
Given the requests, determine whether the system accepts or rejects each one.
Input
The first line contains integers and ().
Each of the next lines contains a room number () and integers and (), the start and end times of the -th reservation. The reservations are given in ascending order of , and no two share the same start time.
Output
Print lines. For each request in order, print YES if the system accepts it, or NO if it rejects it.
Hint
Slow input and output can cause a time limit exceeded when reading or printing many lines.
If you use C++ with cin and cout, apply both cin.tie(NULL) and sync_with_stdio(false), and write \n instead of endl. After this, do not use C-style I/O such as scanf, printf, puts, getchar, or putchar.
If you use Java, you can use BufferedReader and BufferedWriter instead of Scanner and System.out.println. Call BufferedWriter.flush only once, at the end.
If you use Python, you can use sys.stdin.readline instead of input. It keeps the trailing newline, so call .rstrip() when you store a string.