#C557. Maximum Tasks Scheduling

    ID: 49233 Type: Default 1000ms 256MiB

Maximum Tasks Scheduling

Maximum Tasks Scheduling

You are given a list of tasks. Each task is represented by a deadline \(d\) and the time required \(t\) to complete it. Your objective is to complete as many tasks as possible such that each task is finished before or at its deadline. Formally, if the current time is \(T\) and a task requires \(t_i\) time and has a deadline \(d_i\), then the task can be completed if \(T + t_i \le d_i\). This problem can be solved using a greedy strategy.

The tasks should be scheduled in the order of increasing deadlines. In case of a tie in deadlines, the task with the shorter processing time should be considered first.

inputFormat

The first line contains an integer n, representing the number of tasks. Each of the following n lines contains two space-separated integers: the deadline and the time required for that task.

outputFormat

A single integer representing the maximum number of tasks that can be completed.## sample

3
4 3
2 2
3 1
2