#C2744. Maximize Non-Overlapping Events Scheduling

    ID: 46094 Type: Default 1000ms 256MiB

Maximize Non-Overlapping Events Scheduling

Maximize Non-Overlapping Events Scheduling

You are given n classrooms and m events. Each event is specified by three integers: the classroom number c, the start time s, and the end time e. Two events overlap if they are in the same classroom and their time intervals intersect. Your task is to schedule as many events as possible such that no two events in the same classroom overlap.

Mathematically, for each classroom i, consider a set of events with intervals \( [s,e] \). The goal is to select a subset of these intervals such that for any two intervals \( [s_1,e_1] \) and \( [s_2,e_2] \) in the subset, the condition \( s_2 \ge e_1 \) (after sorting by end times) holds. The overall objective is to maximize the total number of events scheduled across all classrooms.

You are required to read input from stdin and output the result to stdout.

inputFormat

The input format is as follows:

<n> <m>
<c1> <s1> <e1>
<c2> <s2> <e2>
...
<cm> <sm> <em>

Where:

  • n is the number of classrooms.
  • m is the number of events.
  • Each event is represented by three integers: c (the classroom number), s (the start time), and e (the end time).

outputFormat

Output a single integer representing the maximum number of non-overlapping events that can be scheduled across all classrooms.

## sample
2 3
1 1 5
1 2 6
2 1 3
2

</p>