#K796. Job Offer Scheduling
Job Offer Scheduling
Job Offer Scheduling
You are given N job offers. Each job offer is represented by a start time and an end time. Your task is to choose the maximum number of non-overlapping job offers such that you can attend each of them fully.
You can only attend a job if its start time is not earlier than the finish time of the last job you decided to attend. Formally, if you have accepted a job that finishes at time t, you can accept another job if its start time satisfies \(s \ge t\).
The problem can be modeled as an activity selection problem where a greedy algorithm that sorts the jobs by their end times yields the optimal solution.
inputFormat
The first line contains a single integer N (1 \(\le\) N \(\le\) 105), representing the number of job offers.
Each of the following N lines contains two space-separated integers s and e (1 \(\le s < e \le\) 109), representing the start time and end time of a job offer.
outputFormat
Output a single integer: the maximum number of non-overlapping job offers that can be accepted.
## sample3
1 3
2 5
4 6
2
</p>