QOJ.ac

QOJ

时间限制: 3 s 内存限制: 1024 MB 总分: 100

#9183. 花束

统计

在参观完世界最大的花卉园之一库肯霍夫(Keukenhof)后,Lieke 变得非常喜爱花卉,因此她决定采集一些长在路边的郁金香来制作一束美丽的花束。然而,在采集花卉时,由于荷兰严格的郁金香保护法,她必须遵守一些规则。

路边按从左到右的顺序生长着 $N$ 株郁金香,编号为 $0$ 到 $N - 1$。郁金香保护法为每株郁金香 $i$ 指定了两个整数 $l_i$ 和 $r_i$。如果郁金香 $i$ 被包含在花束中,那么紧邻郁金香 $i$ 左侧的 $l_i$ 株郁金香和紧邻郁金香 $i$ 右侧的 $r_i$ 株郁金香都不能被包含在花束中。注意,如果郁金香 $i$ 左侧不足 $l_i$ 株或右侧不足 $r_i$ 株,则该侧所有郁金香仍会被排除在花束之外(允许溢出)。

Lieke 想知道,如果她以最优方式采摘,她最多能采摘多少株郁金香。请通过找到这个问题的答案来帮助她制作一束美丽的花束!

输入格式

输入的第一行包含一个整数 $N$,表示沿路生长的郁金香数量。

接下来的 $N$ 行描述了郁金香保护法的信息:第 $i$ 行包含两个整数 $l_i$ 和 $r_i$,表示郁金香 $i$ 的保护约束。

输出格式

输出一个整数,表示 Lieke 在遵守保护法的前提下最多能采摘的郁金香数量。

数据范围

  • $1 \le N \le 2 \cdot 10^5$
  • $0 \le l_i, r_i \le N$,对于 $i = 0, 1, \dots, N - 1$。

你的解法将在多组测试数据上进行测试,每组测试数据包含若干测试点。要获得某一组测试数据的分数,你需要通过该组内的所有测试点。

子任务 分值 限制
1 8 $l_i = r_i = l_j = r_j$,对于所有对 $(i, j)$
2 16 $r_i = 0$,对于所有 $i$
3 28 $N \le 1000$
4 18 $l_i, r_i \le 2$,对于所有 $i$
5 30 无附加限制

样例

注意,部分样例对于所有子任务来说可能不是有效的输入。

在第一个样例中,如果 Lieke 采摘了郁金香 $0$,她就不能采摘右侧的两株郁金香。采摘郁金香 $1$ 并不禁止她采摘郁金香 $2$,但郁金香 $2$ 禁止她采摘郁金香 $1$,因此她不能同时采摘这两株。所以,Lieke 最多能采摘的花卉数量为 $1$。

在第二个样例中,Lieke 最多能采摘的郁金香数量为 $3$,获取方式如图所示。其他采摘方式得到的结果均较小。

在第三个样例中,通过采摘郁金香 $0, 1, 3$ 和 $6$,可以获得最多 $4$ 株郁金香。

输入格式 1

3
0 3
1 0
1 0

输出格式 1

1

输入格式 2

5
0 3
1 0
0 1
2 0
1 0

输出格式 2

3

输入格式 3

7
0 0
0 0
1 0
1 0
2 0
3 0
2 0

输出格式 3

4

输入格式 4

6
2 2
2 2
2 2
2 2
2 2
2 2

输出格式 4

2

输入格式 5

7
0 2
2 0
1 1
2 2
0 0
0 1
0 1

输出格式 5

3

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.