atcoder#AGC053D. [AGC053D] Everyone is a winner

[AGC053D] Everyone is a winner

Score : 10001000 points

Problem Statement

We have a contest with NN participants and NN problems. The participants are numbered 11 through NN. For each pair of a participant and a problem, we know the time it takes for the participant to solve the problem, and it is 11, 22, or 33 minutes. Among the NN problems, there are AiA_i problems that Participant ii takes 11 minute to solve, BiB_i problems that s/he takes 22 minutes to solve, and CiC_i problems that s/he takes 33 minutes to solve.

Determine whether it is possible for the following to hold for every 1i,jN1 \leq i, j \leq N when the participants can freely decide the order they solve the problems.

  • Let SS be the total time Participant ii takes to solve the first ii problems, and TT be the total time Participant jj takes to solve the first ii problems. Then, we have STS \leq T.

In other words, determine whether it is possible that Participant ii places first (possibly with ties) when they have solved the first ii problems, ignoring the time it takes for them to switch between problems.

Given TT test cases, solve each of them.

Constraints

  • 1T2×1051 \leq T \leq 2\times 10^5
  • 1N2×1051 \leq N \leq 2\times 10^5
  • 0Ai,Bi,CiN0 \leq A_i,B_i,C_i \leq N
  • Ai+Bi+Ci=NA_i+B_i+C_i=N
  • The sum of NN over all test cases is at most 2×1052\times 10^5.

Input

Input is given from Standard Input in the following format. The first line is as follows:

TT

Then, TT test cases follow, each in the format below:

NN

A1A_1 B1B_1 C1C_1

::

ANA_N BNB_N CNC_N

Output

For each test case, print Yes if the condition in Problem Statement can be satisfied, and print No otherwise. Use one line for each test case. (The checker is case-insensitive: we will accept both uppercase and lowercase letters.)

2
3
0 2 1
0 1 2
1 1 1
3
0 2 1
0 0 3
1 1 1
Yes
No

In the first test case, one scenario that satisfies the condition is as follows:

  • Participant 11 solves the first problem in 33 minutes, the second in 22 minutes, and the third in 22 minutes;
  • Participant 22 solves the first problem in 33 minutes, the second in 22 minutes, and the third in 33 minutes;
  • Participant 33 solves the first problem in 33 minutes, the second in 22 minutes, and the third in 11 minutes.