#K64167. Maximum Non-overlapping Interviews

    ID: 31916 Type: Default 1000ms 256MiB

Maximum Non-overlapping Interviews

Maximum Non-overlapping Interviews

You are given a set of n interview time slots. Each slot is represented as a pair of integers \( (s_i, e_i) \) corresponding to its start time and end time respectively. Two intervals \( (s_i, e_i) \) and \( (s_j, e_j) \) are non-overlapping if \( s_j \ge e_i \) when the intervals are sorted by their ending times. Your task is to select the maximum number of non-overlapping intervals from the given set.

Note: The input is provided via standard input (stdin) and the required output should be written to standard output (stdout). Make sure that your program reads all input from stdin and writes the answer to stdout.

Example:

Input:
3
1 2
2 3
3 4

Output: 3

</p>

inputFormat

The first token is an integer \( n \) representing the number of intervals. This is followed by \( 2n \) integers where every adjacent pair represents an interval's start time and end time.

For example, an input of:

3
1 2
2 3
3 4

corresponds to three intervals: \( (1,2) \), \( (2,3) \), and \( (3,4) \).

outputFormat

Output a single integer representing the maximum number of non-overlapping intervals that can be selected.

## sample
3
1 2
2 3
3 4
3

</p>