408820: GYM103329 E Median

Memory Limit:0 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E. Mediantime limit per test2 secondsmemory limit per test512 mebibytesinputstandard inputoutputstandard output

Mr. Docriz has $$$n$$$ different kinds of objects indexed by $$$1, 2, \ldots, n$$$. An object of the $$$i$$$-th kind weighs $$$i$$$ kilograms. For each $$$i$$$, Mr. Docriz has $$$b_i$$$ objects of the $$$i$$$-th kind. Among those objects, there are $$$a_i$$$ precious objects, and the remaining ones are common objects. Now, he wants to divide all his objects into some (one or more) disjoint sets. These sets have to satisfy the following conditions:

  1. Each object should go to exactly one set.
  2. Each set should contain exactly one precious object.
  3. In each set, the weight of the precious object should be the median weight of this set.

Please tell him whether it is possible.

For a set of size $$$k$$$, if we sort its elements by non-descending weight as $$$c_1, c_2, \ldots, c_k$$$, the median weight of this set is defined as the weight of $$$c_{\lfloor (k + 1) / 2 \rfloor}$$$.

Input

The first line contains an integer $$$T$$$ ($$$1 \leq T \leq 1000$$$), the number of test cases. Then $$$T$$$ test cases follow.

The first line of each test case contains one integer $$$n$$$ ($$$1 \leq n \leq 10^6$$$), specifying how many different kinds of objects Mr. Docriz has.

Then $$$n$$$ lines follow. The $$$i$$$-th of these lines contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$0 \leq a_i \leq b_i \leq 10^9$$$), indicating that there are $$$a_i$$$ precious objects of the $$$i$$$-th kind, and $$$b_i$$$ objects of the $$$i$$$-th kind in total.

It is guaranteed that $$$\sum n \leq 2 \cdot 10^6$$$.

Output

For each test case, output "YES" if it is possible to achieve the goal, or "NO" otherwise.

ExampleInput
3
4
1 1
1 1
1 1
1 1
4
1 1
0 1
1 1
1 1
4
0 1
1 1
1 1
1 1
Output
YES
YES
NO

加入题单

算法标签: