QOJ.ac

QOJ

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

#11054. 张贴海报

الإحصائيات

Byteburg 东区的建筑都是按照古老的建筑风格建造的:它们彼此紧挨着,中间没有任何间隙。它们共同构成了一条从东向西延伸的、高度各异的超长建筑链。

Byteburg 的市长 Byteasar 决定用海报覆盖这条建筑链的北侧墙面。Byteasar 正在思考覆盖整个北侧墙面所需的最少海报数量。海报呈矩形,边与地面垂直或平行。海报之间不能重叠,但可以接触,即可以在边上拥有公共点。每一张海报都必须完全贴合某些建筑的墙面,且北侧墙面的整个表面都必须被覆盖。

请编写一个程序:

  • 从标准输入读取建筑的描述,
  • 确定完全覆盖其北侧墙面所需的最少海报数量,
  • 将结果输出到标准输出。

输入格式

标准输入的第一行包含一个整数 $n$ ($1 \le n \le 250\,000$),表示建筑链中建筑的数量。接下来的 $n$ 行中,每行包含两个整数 $d_i$ 和 $w_i$ ($1 \le d_i, w_i \le 1\,000\,000\,000$),由单个空格分隔,分别表示第 $i$ 座建筑的宽度和高度。

输出格式

标准输出的第一行也是唯一一行应包含一个整数,即覆盖建筑北侧墙面所需的最少矩形海报数量。

样例

输入 1

5
1 2
1 3
2 2
2 5
1 4

输出 1

4

说明

这些图片展示了建筑链的北侧墙面。第二张图片展示了用四张海报覆盖该墙面的一个示例。

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.