Monster Fighting
면접 대비시간 제한2초메모리 제한256 MB
각각 타입과 전투력을 가진 아군 몬스터 N마리와 적 몬스터 N마리가 주어질 때, 전투력이 상대 이상이거나 같은 타입이면서 절반 이상이면 이기는 조건으로 완전 매칭이 존재하는지 판정한다.
문제
Busy Beaver is playing his favorite adventure game, where he battles wild monsters with monsters of his own!
In this game, there are two types of monsters: light and dark. Each monster has exactly one type, and some positive integer power level. A monster with power can defeat another monster if either , or if they have the same type and .
Busy Beaver has just encountered monsters, and he also has monsters in his party. To defend against the encounter, he needs to pair his monsters with the opposing monsters such that in each pair, Busy Beaver's monster can defeat the opposing monster according to the rules above. Given the types and power levels of each of the monsters, please report whether or not such a pairing exists.
입력
Each test contains multiple test cases. The first line of input contains a single integer , the number of test cases. The description of each test case follows.
The first line of each test case contains a single positive integer ().
Then, lines of input follow, describing Busy Beaver's monsters. The th line contains two positive integers () --- the power level and type of the th monster. denotes a light-type monster, and denotes a dark-type monster.
After that, there are more lines of input, describing the encountered monsters. The th line contains two positive integers () --- the power level and type of the th monster. denotes a light-type monster, and denotes a dark-type monster.
It is guaranteed that the sum of across all test cases is no more than .
출력
For each test case, output "YES" (without quotes) if a desired pairing exists, and "NO" (without quotes) otherwise.
힌트
In the sample input, there are two test cases. For the first case, we can construct a pairing as follows:
- Your light type monster of power level can defeat the identical opposing monster.
- Your light type monster of power level can defeat the identical opposing monster.
- Your first dark type monster of power level can defeat the opposing dark type monster of power level .
- Your second dark type monster of power level can defeat the opposing light type monster of power level .
In the second case, it can be shown that no pairing exists.