100 atcoder#ABC214E. [ABC214E] Packing Under Range Regulations

[ABC214E] Packing Under Range Regulations

Score : 500500 points

Problem Statement

Solve the following problem for TT test cases.

There are 10910^9 boxes numbered 1,2,,1091,2,\dots,10^9 and NN balls numbered 1,2,,N1,2,\dots,N. Each box can contain at most one ball. Determine whether it is possible to put all NN balls in the boxes so that the following condition will be satisfied.

  • For each integer ii from 11 through NN, the ball numbered ii is in a box numbered between LiL_i and RiR_i (inclusive).

Constraints

  • 1T2×1051 \le T \le 2 \times 10^5
  • 1N2×1051 \le N \le 2 \times 10^5
  • 1LiRi1091 \le L_i \le R_i \le 10^9
  • The sum of NN across the test cases in one input is at most 2×1052 \times 10^5.

Input

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

TT

Then, TT test cases follows, each of which is in the following format:

NN

L1L_1 R1R_1

L2L_2 R2R_2

\dots

LNL_N RNR_N

Output

Your output should have TT lines. In the ii-th (1iT)(1 \le i \le T) line, print Yes if it is possible to put all NN balls in the boxes so that the condition will be satisfied in the ii-th test case in the input, and printNo otherwise. The checker is case-insensitive; it will accept both uppercase and lowercase letters.

2
3
1 2
2 3
3 3
5
1 2
2 3
3 3
1 3
999999999 1000000000
Yes
No

This input contains two test cases.

  • In the 11-st test case, the following way to put the three balls would satisfy the condition, so we should print Yes.
    • Put Ball 11 in Box 11.
    • Put Ball 22 in Box 22.
    • Put Ball 33 in Box 33.
  • In the 22-nd test case, there is no way to put the five balls to satisfy the condition, so we should print No.