#K16226. Deadline Task Completion

    ID: 24532 Type: Default 1000ms 256MiB

Deadline Task Completion

Deadline Task Completion

You are given several sets of tasks. For each set, each task is characterized by a deadline and the time required (duration) to complete it. Your objective is to determine the maximum number of tasks that can be completed sequentially (one after another) such that each task is finished no later than its deadline.

You may choose the tasks in any order, but once a task is started it must complete without interruption. A common greedy strategy is to sort the tasks by their deadlines and durations and schedule tasks if the cumulative time plus the task's duration does not exceed its deadline. In mathematical terms, if t is the current elapsed time and a task has a deadline D and duration L, then the task can be performed if

\( t + L \le D \)

If the task is performed, update \( t \) to \( t + L \) and count the task as completed. Print the count of tasks executed for each test case on a new line.

inputFormat

The input begins with an integer \( T \) representing the number of test cases. Each test case starts with an integer \( N \) (the number of tasks). The following \( N \) lines each contain two space-separated integers representing the deadline and duration of a task.

Example:

2
3
3 2
1 2
2 1
4
4 2
2 2
3 1
1 1

outputFormat

For each test case, output a single integer on a new line indicating the maximum number of tasks that can be completed before their deadlines.

Example Output:

2
3
## sample
2
3
3 2
1 2
2 1
4
4 2
2 2
3 1
1 1
2

3

</p>