QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100

#871. 有趣的计分系统

统计

在国际象棋锦标赛中,计分方式一直是一个有争议的话题。Abel 喜欢经典计分系统:胜者得 2 分,平局各得 1 分。Bolzano 则更喜欢足球计分方式:胜者得 3 分,平局各得 1 分。但 Cardano 对这两种方式都不满意,他有自己的一套判定胜者的方法。我们定义锦标赛的图为:每个节点代表一名选手,如果选手 $v$ 至少赢过选手 $u$ 一次,则存在一条从 $v$ 到 $u$ 的有向边。Cardano 认为,一名选手 $v$ 赢得锦标赛的唯一条件是:在锦标赛的图中,存在从 $v$ 到其他所有选手的路径,且不存在从其他任何选手到 $v$ 的路径。

最近举行了一场有 $n$ 名选手的国际象棋锦标赛,选手编号从 $0$ 到 $n-1$。我们唯一掌握的信息是每名选手按照 Abel 和 Bolzano 的计分标准所获得的分数。每名选手可能与任何其他选手进行了任意次数的比赛。请确定是否存在一种可能,使得选手 $0$ 按照 Cardano 的标准赢得了锦标赛。

输入格式

第一行包含一个整数 $t$,表示测试用例的数量 ($1 \le t \le 10^4$)。每个测试用例包含三行: 第一行包含一个整数 $n$ ($1 \le n \le 10^6$),表示锦标赛的参赛人数。 第二行包含 $n$ 个整数 $a_0, a_1, \dots, a_{n-1}$ ($0 \le a_i \le 10^9$),其中 $a_i$ 是选手 $i$ 按照 Abel 的标准获得的分数。 第三行包含 $n$ 个整数 $b_0, b_1, \dots, b_{n-1}$ ($0 \le b_i \le 10^9$),其中 $b_i$ 是选手 $i$ 按照 Bolzano 的标准获得的分数。

所有测试用例的 $n$ 之和不超过 $10^6$。 保证给出的分数对应于一场合法的锦标赛。

输出格式

对于每个测试用例,如果选手 $0$ 有可能按照 Cardano 的标准赢得锦标赛,则输出一行 "YES"。否则,输出一行 "NO"。

样例

输入 1

2
3
4 1 1
6 1 1
4
5 1 1 1
7 1 1 1

输出 1

YES
NO

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.