QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 512 MB مجموع النقاط: 100

#1126. 汇款

الإحصائيات

在 JOI 王国的海狸湖周围有 $N$ 座房子,按逆时针方向编号为 $1$ 到 $N$。

每座房子都可以使用汇款服务向其在湖边视角下的左侧相邻房子汇款(对于第 $i$ 座房子($1 \le i \le N-1$),其左侧相邻房子是第 $i+1$ 座;对于第 $N$ 座房子,其左侧相邻房子是第 $1$ 座)。然而,汇款需要支付手续费,手续费金额与汇款金额相同。汇款必须以 $1$ 日元为单位。当你汇款时,你必须支付手续费,因此汇款金额与手续费之和不能超过该房子现有的金额。

目前,第 $i$ 座房子($1 \le i \le N$)拥有 $A_i$ 日元。另一方面,从税收措施的角度来看,希望第 $i$ 座房子的金额等于 $B_i$ 日元。你希望通过使用汇款服务,使每座房子的金额都等于 $B_i$ 日元。除了支付手续费外,你不能将钱用于其他用途,也不能通过汇款服务以外的方式汇款。

给定所有房子的当前金额和目标金额,请编写一个程序,判断是否可以通过使用汇款服务使所有房子的金额达到目标金额。

输入格式

从标准输入读取以下数据:

$N$ $A_1$ $B_1$ $A_2$ $B_2$ $\vdots$ $A_N$ $B_N$

输出格式

如果可以通过使用汇款服务使所有房子的金额达到目标金额,则输出 Yes,否则输出 No

数据范围

  • $2 \le N \le 1\,000\,000$
  • $0 \le A_i \le 1\,000\,000\,000$ ($1 \le i \le N$)
  • $0 \le B_i \le 1\,000\,000\,000$ ($1 \le i \le N$)

子任务

  1. (15 分) $N \le 7$, $A_i \le 5$, $B_i \le 5$ ($1 \le i \le N$)。
  2. (40 分) $N \le 20$。
  3. (45 分) 无附加限制。

样例

样例输入 1

5
0 0
1 0
2 3
3 3
4 0

样例输出 1

Yes

说明

例如,通过以下方式使用汇款服务,可以使所有房子的金额达到目标金额:

  1. 从第 $5$ 座房子向第 $1$ 座房子汇款 $2$ 日元。手续费为 $2$ 日元。
  2. 从第 $1$ 座房子向第 $2$ 座房子汇款 $1$ 日元。手续费为 $1$ 日元。
  3. 从第 $2$ 座房子向第 $3$ 座房子汇款 $1$ 日元。手续费为 $1$ 日元。

样例输入 2

5
0 0
1 2
2 4
3 2
4 0

样例输出 2

No

样例输入 3

2
1 1
2 1

样例输出 3

No

说明

注意汇款必须以 $1$ 日元为单位。

样例输入 4

2
1 1
2 2

样例输出 4

Yes

说明

你不需要使用汇款服务。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.