#K85027. Maximum Concurrent Sessions
Maximum Concurrent Sessions
Maximum Concurrent Sessions
You are given n user sessions where each session is represented by its start time si and end time ei. Two sessions are considered concurrent if they overlap in time. In other words, a session starting exactly when another session ends is not considered overlapping. Your task is to determine the maximum number of sessions that are active at the same time.
The problem can be summarized by finding the maximum value of the function:
$$\max_{t} C(t)$$
where C(t) is the number of sessions active at time t. Use a sweep-line algorithm that processes the start and end events of each session. Make sure to process end events before start events if they occur at the same time so that overlapping is correctly handled.
inputFormat
The input is read from stdin and has the following format:
n s1 e1 s2 e2 ... sn en
Where n
is the number of sessions, and each of the next n
lines contains two space-separated integers representing the start time si and end time ei of a session.
outputFormat
Output to stdout a single integer, which is the maximum number of concurrent sessions.
## sample3
1 5
2 6
4 8
3