#C2957. Maximum Overlapping Tasks

    ID: 46330 Type: Default 1000ms 256MiB

Maximum Overlapping Tasks

Maximum Overlapping Tasks

You are given a list of tasks, each specified by a start time and an end time. The goal is to determine the maximum number of tasks that overlap at any given moment.

Formally, for each task represented by an interval \([s_i, e_i]\), we define an event at time \(s_i\) that increases the count by 1 and an event at time \(e_i\) that decreases the count by 1. The answer is the maximum cumulative count over time, i.e., \[ \text{max extunderscore overlapping} = \max_{t} \sum_{i} \mathbf{1}_{t \in [s_i,e_i)} \]

Input is given via standard input (stdin) and the answer should be printed to standard output (stdout).

inputFormat

The first line of input contains a single integer \(n\) \( (1 \leq n \leq 10^5)\), the number of tasks. The following \(n\) lines each contain two integers \(s_i\) and \(e_i\) representing the start time and end time of a task.

Input Format:

n
s₁ e₁
s₂ e₂
... 
sₙ eₙ

outputFormat

Print a single integer representing the maximum number of overlapping tasks at any given time.

Output Format:

max_overlapping
## sample
3
1 3
2 5
4 6
2

</p>