아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Interesting Scoring Systems

시간 제한1초메모리 제한512 MB

요약
승리에 2점과 3점을 주는 두 기준의 점수가 주어질 때, 선수 0이 토너먼트 그래프의 유일한 출발점이 될 수 있는지 판정한다.
난이도

보통10점 중 7점

유형
그래프, 그리디, 수학
정답자
아직 제출이 없습니다

문제

Score in chess tournaments is a controversial topic. Abel likes the classical system: 2 points per win and 1 point per draw. Bolzano prefers the football way: 3 points per win and 1 point per draw. But Cardano doesn't like either way and has his own system to declare a winner. We define the graph of the tournament as the graph where each node represents a player and an edge goes from player vv to player uu if player vv won at least one game against player uu. Then Cardano states that a player vv wins the tournament only if in the graph of the tournament there is a path from vv to everyone else and there is none from any other player to vv.

Recently, there has been a chess tournament of nn players, numbered from 00 to n−1n-1. The only information we have is the number of points of each player according to Abel's and Bolzano's criteria. Each player might have played any number of times with any other player. Determine if it is possible that player 00 won the tournament according to Cardano's criteria.

입력

The first line contains one integer tt, the number of test cases (1≤t≤1041 \leq t \leq 10^4). Each test case consists of three lines:

The first line of contains one integer nn (1≤n≤1061 \leq n \leq 10^6), the number of participants in the tournament.

The second line contains nn integers a_0,a_1,…,a_n−1a\_0, a\_1, \dots, a\_{n-1} (0≤a_i≤1090 \leq a\_i \leq 10^9), where a_ia\_i is the number of points player ii has obtained according to Abel's criteria.

The third line contains nn integers b_0,b_1,…,b_n−1b\_0, b\_1, \dots, b\_{n-1} (0≤b_i≤1090 \leq b\_i \leq 10^9), where b_ib\_i is the number of points player ii has obtained according to Bolzano's criteria.

The sum of nn for all test cases won't exceed 10610^6.

It is guaranteed that the given scoring corresponds to a valid tournament.

출력

For each test case, print a line with the word "YES" if it is possible that player 00 won the tournament according to Cardano's criteria. Otherwise, print a line with the word "NO".

예제1

  1. 예제 1

    입력
    2
    3
    4 1 1
    6 1 1
    4
    5 1 1 1
    7 1 1 1
    
    예상 출력
    YES
    NO