QOJ.ac

QOJ

Limite de temps : 2 s Limite de mémoire : 512 MB Points totaux : 100

#1867. 中位数

Statistiques

Mr. Docriz 有 $n$ 种不同的物品,编号为 $1, 2, \dots, n$。第 $i$ 种物品的重量为 $i$ 千克。对于每个 $i$,Mr. Docriz 拥有 $b_i$ 个第 $i$ 种物品。在这些物品中,有 $a_i$ 个是珍贵物品,其余的是普通物品。现在,他想将他所有的物品分成若干个(一个或多个)不相交的集合。这些集合必须满足以下条件:

  1. 每个物品必须恰好属于一个集合。
  2. 每个集合必须恰好包含一个珍贵物品。
  3. 在每个集合中,珍贵物品的重量必须是该集合的中位数重量。

请告诉他这是否可行。

对于一个大小为 $k$ 的集合,如果我们将其元素按重量非降序排列为 $c_1, c_2, \dots, c_k$,则该集合的中位数重量定义为 $c_{(k+1)/2}$ 的重量。

输入格式

第一行包含一个整数 $T$ ($1 \le T \le 1000$),表示测试用例的数量。接下来是 $T$ 个测试用例。 每个测试用例的第一行包含一个整数 $n$ ($1 \le n \le 10^6$),表示 Mr. Docriz 拥有的物品种类数。 接下来 $n$ 行,第 $i$ 行包含两个整数 $a_i$ 和 $b_i$ ($0 \le a_i \le b_i \le 10^9$),表示第 $i$ 种物品中有 $a_i$ 个珍贵物品,且第 $i$ 种物品总共有 $b_i$ 个。 保证 $\sum n \le 2 \cdot 10^6$。

输出格式

对于每个测试用例,如果可以实现目标,输出 “YES”,否则输出 “NO”。

样例

输入 1

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

输出 1

YES
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.