#K59542. Maximum Simultaneous Unguarded Exhibits
Maximum Simultaneous Unguarded Exhibits
Maximum Simultaneous Unguarded Exhibits
You are given a museum scenario, where there are n exhibits and m time intervals. Each interval represents the time during which a specific exhibit is unguarded. Specifically, each interval is given in the format [exhibit_id, start, end]. Although the exhibit identifier is provided, what matters is the time range when the exhibit is unguarded. Your task is to determine the maximum number of exhibits that are unguarded simultaneously.
The problem can be formalized as follows:
Given m intervals, find the maximum overlap count:
$$\max_{t}\sum_{i=1}^{m} 1_{\{t \in [s_i, e_i]\}}$$
where \(s_i\) and \(e_i\) denote the start and end times of the i-th interval, respectively, and \(1_{\{\cdot\}}\) is the indicator function.
This problem can be solved efficiently with a sweep line algorithm.
inputFormat
The first line of the input contains two integers n
and m
, where n
is the total number of exhibits (although this value is not directly used in determining the answer) and m
is the number of intervals provided.
Each of the following m
lines contains three space-separated integers: exhibit_id
, start
, and end
, representing the identifier for an exhibit and the start and end times during which the exhibit is unguarded.
Input is read from standard input.
outputFormat
Output a single integer representing the maximum number of exhibits that are unguarded simultaneously during any time interval.
Output should be written to standard output.
## sample5 4
1 1 5
2 2 6
3 3 7
4 4 8
4