#P9241. [蓝桥杯 2023 省 B] 飞机降落

[蓝桥杯 2023 省 B] 飞机降落

Problem Description

There are NN airplanes preparing to land at an airport with only one runway. For airplane ii, it arrives above the airport at time TiT_{i}. When it arrives, its remaining fuel allows it to keep circling for another DiD_{i} units of time. That is, it can start landing as early as time TiT_{i}, and as late as time Ti+DiT_{i}+D_{i}. The landing process takes LiL_{i} units of time.

When one airplane finishes landing, another airplane may start landing immediately at the same moment. However, no airplane may start landing before the previous airplane has finished landing.

Determine whether all NN airplanes can land safely.

Input Format

The input contains multiple test cases.

The first line contains an integer TT, representing the number of test cases.

For each test case, the first line contains an integer NN.

The following NN lines each contain three integers Ti,Di,LiT_{i}, D_{i}, L_{i}.

Output Format

For each test case, output YES or NO, indicating whether all airplanes can land safely.

2
3
0 100 10
10 10 10
0 2 20
3
0 10 20
10 10 20
20 10 20
YES
NO

Hint

Sample Explanation

For the first test case, you can schedule airplane 3 to start landing at time 0 and finish at time 20. Schedule airplane 2 to start landing at time 20 and finish at time 30. Schedule airplane 1 to start landing at time 30 and finish at time 40.

For the second test case, no matter how you schedule, there will always be an airplane that cannot land in time.

Constraints and Notes

For 30%30\% of the testdata, N2N \leq 2.

For 100%100\% of the testdata, 1T101 \leq T \leq 10, 1N101 \leq N \leq 10, 0Ti,Di,Li1050 \leq T_{i}, D_{i}, L_{i} \leq 10^{5}.

Lanqiao Cup 2023 Provincial Contest B Group Problem D.

Translated by ChatGPT 5