#K66332. Maximum Non-Overlapping Meetings

    ID: 32397 Type: Default 1000ms 256MiB

Maximum Non-Overlapping Meetings

Maximum Non-Overlapping Meetings

You are given a set of meetings, each with a start time and an end time. Your task is to determine the maximum number of meetings that can be scheduled without any overlaps. Two meetings are non-overlapping if the start time of the current meeting is greater than or equal to the end time of the previous scheduled meeting. Mathematically, if a meeting ends at time ( e ), then the next meeting can start at any time ( s ) provided that ( s \geq e ).

Example: For the meetings ((1,3)), ((2,5)), and ((4,6)), the maximum number of non-overlapping meetings is 2 (by choosing meetings ((1,3)) and ((4,6))).

inputFormat

The input is given via standard input (stdin). The first line contains an integer ( n ) representing the number of meetings. Each of the following ( n ) lines contains two integers, representing the start time and end time of a meeting, separated by a space.

outputFormat

Output a single integer representing the maximum number of non-overlapping meetings that can be scheduled. The output should be written to standard output (stdout).## sample

3
1 3
2 5
4 6
2