QOJ.ac

QOJ

Limite de temps : 0.35 s Limite de mémoire : 1024 MB Points totaux : 100

#8510. 公平分配

Statistiques

一位企业家拥有 $N$ 张蓝图,每张蓝图描述了一种建筑类型。每张蓝图通过两个整数 $G$ 和 $R$ 来指定建筑的高度。

  • $G$:底楼高度。它可以为零,表示该建筑没有底楼。
  • $R$:每层住宅楼的高度。每栋建筑至少有一层住宅楼。

企业家希望将所有这些蓝图分配给他的两个孩子 Alice 和 Bob。每个孩子将根据分配给他们的每张蓝图各建造一栋建筑,并为每栋建筑选择住宅楼的层数。

企业家希望避免偏袒任何一个孩子,因此他正在寻找一种公平的蓝图分配方式。他们认为,如果能够以某种方式建造建筑,使得每个孩子建造的建筑高度之和相等,那么这种分配就是公平的。你能判断是否存在一种公平的分配方式吗?

考虑 $N = 3$ 张蓝图的以下示例:

  1. $G = 1$ 且 $R = 1$(可能的高度为 $2, 3, 4, \dots$);
  2. $G = 0$ 且 $R = 3$(无底楼,可能的高度为 $3, 6, 9, \dots$);
  3. $G = 2$ 且 $R = 1$(可能的高度为 $3, 4, 5, \dots$)。

在这种情况下,一种可能的公平分配是将第二张蓝图分配给 Alice,其余的分配给 Bob。尽管 Alice 只收到一张蓝图而 Bob 收到两张,但他们可以分别为第一种建筑类型建造两层住宅(高度 3),为第二种建造两层住宅(高度 6),为第三种建造一层住宅(高度 3)。这样,每个孩子建造的建筑高度之和都将是 6。

输入格式

第一行包含一个整数 $N$ ($1 \le N \le 2 \cdot 10^5$),表示蓝图的数量。

接下来的 $N$ 行,每行包含两个整数 $G$ ($0 \le G \le 2 \cdot 10^5$) 和 $R$ ($1 \le R \le 10^9$),分别表示相应蓝图指定的底楼高度和每层住宅楼的高度。所有蓝图的底楼高度之和最多为 $2 \cdot 10^5$。

输出格式

如果存在一种公平的蓝图分配方式,输出一行,包含大写字母“Y”,否则输出大写字母“N”。

样例

输入 1

3
1 1
0 3
2 1

输出 1

Y

输入 2

3
3 2
2 1
3 2

输出 2

Y

输入 3

3
1 10
2 20
4 30

输出 3

N

输入 4

1
1 1

输出 4

N

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.