#K34577. Session Scheduling
Session Scheduling
Session Scheduling
You are given N sessions and M rooms. Each session is defined by two integers representing its start and end times. Your task is to determine if it is possible to schedule all sessions in the available rooms so that no two sessions in the same room overlap.
Note: Sessions can only be scheduled in a room if the room is empty or the previous session in that room has finished by the time the new session starts. Use a greedy strategy by sorting the sessions by their start times and then assigning each session to any room that is available.
Input times are given as integers and can be assumed to be in a valid range.
inputFormat
The input is read from standard input (stdin
) and has the following format:
N M s1 e1 s2 e2 ... sN eN
Here, the first line contains two integers: N (the number of sessions) and M (the number of available rooms). Each of the next N lines contains two space-separated integers representing the start time (s) and end time (e) of a session.
outputFormat
Output a single line to standard output (stdout
). Print Yes
if all sessions can be scheduled without any overlapping in the same room; otherwise, print No
.
3 2
1 5
2 6
6 8
Yes