#K37332. Minimum Resources for Event Scheduling

    ID: 25953 Type: Default 1000ms 256MiB

Minimum Resources for Event Scheduling

Minimum Resources for Event Scheduling

You are given a list of events, each defined by a start time and an end time. Your task is to determine the minimum number of resources required so that all events can be attended without any conflicts.

Two events are said to overlap if one event starts before the other ends. Mathematically, you can express the requirement as:

$$\min\ resources = \max_{t\in \mathbb{R}}\{\text{number of events active at time }t\}.$$

For example, for the events (1, 4), (2, 5), and (7, 9), the minimum number of resources required is 2 because the first two events overlap.

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains a single integer n, denoting the number of events.
  • The next n lines each contain two space-separated integers representing the start time and end time of an event.

outputFormat

Output a single integer to standard output (stdout) denoting the minimum number of resources required to attend all events without conflicts.

## sample
3
1 4
2 5
7 9
2