#K74577. Task Scheduling with Deadlines
Task Scheduling with Deadlines
Task Scheduling with Deadlines
You are given a set of tasks, each with a required execution time and a deadline. Your task is to determine whether it is possible to complete all tasks sequentially without missing any deadlines. In other words, if the tasks are executed in some order, the cumulative execution time at each step must not exceed the corresponding task's deadline.
More formally, for a sequence of tasks sorted in some order, let \(t_i\) be the execution time and \(d_i\) be the deadline of the \(i\)-th task. The schedule is feasible if and only if:
[ \sum_{i=1}^{k} t_i \le d_k \quad \text{for all } k=1,2,\ldots,n. ]
You need to check this feasibility for each test case.
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\) representing the number of tasks.
- The following \(n\) lines each contain two space-separated integers \(t\) and \(d\), where \(t\) is the execution time of a task and \(d\) is its deadline.
Input is read from standard input (stdin).
outputFormat
For each test case, print a single line containing either YES
if it is possible to schedule all tasks meeting their deadlines, or NO
otherwise.
Output is written to standard output (stdout).
## sample2
3
2 10
4 15
3 7
4
1 5
1 10
1 15
1 20
YES
YES
</p>