QOJ.ac

QOJ

時間限制: 3 s 記憶體限制: 2048 MB 總分: 25

#4270. 双重出勤

统计

由于学校的课程安排非常紧凑,你的两门课将在同一时间开始,且分别在两个不同的教室进行!你一次只能在一个地方,所以你最好的希望就是尽可能多地捕捉到两门课的重点,即使这意味着要在两个教室之间来回穿梭。

两个教室编号为 1 和 2。在教室 $i$ 中,老师会在课上展示 $N_i$ 张不同的幻灯片,第 $j$ 张幻灯片在开课后的时间区间 $(A_{i,j}, B_{i,j})$ 内展示($0 \le A_{i,j} < B_{i,j}$),时间以秒为单位。在两门课中,不存在同一时刻展示多张幻灯片的情况。例如,一门课的幻灯片可能跨越区间 $(1, 2)$ 和 $(5, 6)$,或者 $(10, 20)$ 和 $(20, 30)$,但不会是 $(10, 20)$ 和 $(19, 30)$。

你从时间 0 开始在教室 1 上课。此后,你可以在任何时间点(不一定是整数秒)从当前教室移动到另一个教室,移动过程需要 $K$ 秒。如果你在某张幻灯片展示的时间区间内,在对应的教室里停留了正的时间,你就被视为看到了这张幻灯片。在两个教室之间移动时,你在 $K$ 秒内不被视为处于任何一个教室中,因此无法看到任何幻灯片。

例如,如果教室 1 有一张幻灯片在时间区间 $(10, 20)$ 展示,教室 2 有一张幻灯片在时间区间 $(15, 25)$ 展示,且 $K = 8$,那么如果你在时间 11.5 秒离开教室 1(在 19.5 秒到达教室 2),你就能看到这两张幻灯片。另一方面,如果你在 17 秒离开教室 1(在 25 秒到达教室 2),你进入教室 2 时,那张幻灯片的展示时间刚好结束,因此你会错过它。

请问你最多能看到多少张不同的幻灯片?

输入格式

第一行包含三个空格分隔的整数 $N_1, N_2$ 和 $K$。

接下来 $N_1$ 行,每行包含两个空格分隔的整数 $A_{1,i}$ 和 $B_{1,i}$($1 \le i \le N_1$)。

接下来 $N_2$ 行,每行包含两个空格分隔的整数 $A_{2,i}$ 和 $B_{2,i}$($1 \le i \le N_2$)。

子任务

分值 $N_i$ 的范围 $A_{i,j}$ 和 $B_{i,j}$ 的范围 $K$ 的范围
5 分 $1 \le N_i \le 10$ $0 \le A_{i,j} < B_{i,j} \le 2000$ $1 \le K \le 10^9$
10 分 $1 \le N_i \le 2000$ $0 \le A_{i,j} < B_{i,j} \le 2000$ $1 \le K \le 10^9$
6 分 $1 \le N_i \le 2000$ $0 \le A_{i,j} < B_{i,j} \le 10^9$,$B_{i,j} - A_{i,j} \le 2K$ $1 \le K \le 10^9$
4 分 $1 \le N_i \le 300\,000$ $0 \le A_{i,j} < B_{i,j} \le 10^9$ $1 \le K \le 10^9$

输出格式

输出一个整数,表示你能看到的最多的不同幻灯片数量。

样例

样例输入 1

3 1 8
10 20
100 101
20 21
15 25

样例输出 1

3

说明 1

一种可能的最佳策略是:留在教室 1 直到时间 11.5,然后移动到教室 2(在 19.5 到达),留在那里直到时间 19.6,最后回到教室 1(在 27.6 到达)。在此过程中,你看到了除第 3 张以外的所有幻灯片。你不可能看到全部 4 张幻灯片。

样例输入 2

1 5 3
1 100
1 2
2 3
3 4
4 5
5 6

样例输出 2

4

说明 2

即使你在课程开始时立即开始移动到教室 2(例如在时间 0.0001),你也会错过那里展示的前 2 张幻灯片。因此,最多只能看到 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.