Median
시간 제한2초메모리 제한512 MB
무게별로 귀중한 물건 수와 전체 물건 수가 주어질 때, 각 집합이 귀중한 물건 하나를 포함하고 그 무게가 중앙값이 되도록 모든 물건을 나눌 수 있는지 판정한다.
문제
Mr. Docriz has different kinds of objects indexed by . An object of the -th kind weighs kilograms. For each , Mr. Docriz has objects of the -th kind. Among those objects, there are 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:
- Each object should go to exactly one set.
- Each set should contain exactly one precious object.
- 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 , if we sort its elements by non-descending weight as , the median weight of this set is defined as the weight of .
입력
The first line contains an integer (), the number of test cases. Then test cases follow.
The first line of each test case contains one integer (), specifying how many different kinds of objects Mr. Docriz has.
Then lines follow. The -th of these lines contains two integers and (), indicating that there are precious objects of the -th kind, and objects of the -th kind in total.
It is guaranteed that .
출력
For each test case, output "YES" if it is possible to achieve the goal, or "NO" otherwise.