#C6477. Maximum Non-overlapping Meetings

    ID: 50241 Type: Default 1000ms 256MiB

Maximum Non-overlapping Meetings

Maximum Non-overlapping Meetings

You are given several meetings, each with a start time and an end time. Your task is to determine the maximum number of meetings that can be scheduled in a single conference room without any overlaps.

Two meetings do not overlap if the start time of one meeting is not less than the end time of the other. In mathematical terms, if meeting i is represented as \((s_i, f_i)\) and meeting j as \((s_j, f_j)\), then the meetings do not overlap if:

[ s_j \geq f_i ]

It is guaranteed that the end times are positive integers and a meeting ending at time f can be immediately followed by a meeting starting at time f. The input consists of multiple datasets, each ending with a line containing "0".

inputFormat

The input is read from stdin and contains several datasets. Each dataset is formatted as follows:

  • The first line contains an integer n denoting the number of meetings.
  • The next n lines each contain two space-separated integers representing the start and end times of a meeting.
  • A line containing a single 0 indicates the end of input.

Note that there can be multiple datasets in a single input.

outputFormat

For each dataset, output a single integer on a new line representing the maximum number of non-overlapping meetings that can be scheduled in the conference room.

The output is written to stdout.

## sample
4
1 3
2 5
4 6
6 8
0
3

</p>