#K57552. Maximum Conference Sessions
Maximum Conference Sessions
Maximum Conference Sessions
You are given N sessions of a conference. Each session is characterized by its start and end times. Your task is to determine the maximum number of sessions you can attend, given that you cannot attend overlapping sessions. Note that if one session ends exactly when another begins, you can attend both of them consecutively.
The problem can be approached using a greedy scheduling algorithm. Sort the sessions by their end times and select each session that starts after or exactly when the previous session ended.
Formally, if we define a session by an interval \([s_i, e_i]\), then the condition to attend a session after another is \(s_j \ge e_i\).
inputFormat
The first line of input contains a single integer N representing the number of sessions. Each of the following N lines contains two space-separated integers representing the start time and end time of a session.
\(\textbf{Input Format:}\)
N start_1 end_1 start_2 end_2 ... start_N end_N
outputFormat
Output a single integer, which is the maximum number of sessions that can be attended.
\(\textbf{Output Format:}\)
result## sample
4
1 3
2 4
3 5
5 6
3
</p>