#C534. Maximum Non-overlapping Actions
Maximum Non-overlapping Actions
Maximum Non-overlapping Actions
You are given a set of actions for a magician. Each action has a start and end time. The magician can perform actions sequentially as long as the start time of the next action is not earlier than the end time of the previous one. Your task is to determine the maximum number of non-overlapping actions that the magician can perform in each test case.
Formally, for each test case, you are given an integer \(N\) and \(N\) pairs of integers \((s, e)\), representing the start and end times of an action. You need to select as many actions as possible such that no two selected actions overlap. The optimal strategy is to choose actions sorted by their ending time in a greedy manner.
Input/Output details are provided below.
inputFormat
The first line of input contains an integer \(T\), representing the number of test cases. For each test case, the first line contains an integer \(N\), the number of actions. The next \(N\) lines each contain two space-separated integers \(s\) and \(e\), representing the start and end times of an action.
All input is provided via standard input (stdin).
outputFormat
For each test case, output the maximum number of non-overlapping actions that can be performed, each result on a separate line. The output should be sent to standard output (stdout).
## sample2
3
1 2
2 3
3 4
4
1 3
2 4
3 5
6 7
3
3
</p>