#C11664. Maximum Non-Overlapping Tasks Scheduling

    ID: 41005 Type: Default 1000ms 256MiB

Maximum Non-Overlapping Tasks Scheduling

Maximum Non-Overlapping Tasks Scheduling

You are given a set of tasks. Each task is defined by its start time si and its duration di. The finishing time of a task is defined as \( f_i = s_i + d_i \). Two tasks are said to be non-overlapping if the start time of a task is not less than the finishing time of the previously chosen task.

Your goal is to determine the maximum number of non-overlapping tasks that can be scheduled for each test case. This is a classical greedy algorithm problem.

Example: For tasks \((1, 3)\), \((2, 3)\), and \((4, 2)\), one optimal solution selects tasks \((1, 3)\) and \((4, 2)\) to achieve a count of 2.

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains an integer \( T \), the number of test cases.
  • For each test case:
    • The first line contains an integer \( N \), the number of tasks.
    • Each of the following \( N \) lines contains two space-separated integers \( s_i \) and \( d_i \) denoting the start time and duration of the \( i \)-th task.

Note: If \( N = 0 \), then no task lines follow for that test case.

outputFormat

For each test case, output a single line on standard output (stdout) containing one integer, which is the maximum number of non-overlapping tasks that can be scheduled.

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

1 0

</p>