QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#496. 智能游客

Statistics

Johnny 是一位游客,同时也是 Flatland 大学的一名计算机系学生。Johnny 即将面临 $n$ 场考试,因此他需要为这些考试做准备,但他同时还要参加 $m$ 次远足探险。

幸运的是,探险活动的安排使得没有任何考试会与探险时间冲突。然而,备考需要互联网和高度集中,因此在探险期间无法进行备考。Johnny 不能缺席任何一次探险。

Johnny 将所有即将到来的考试从 1 开始编号。对于每场考试,Johnny 都知道它的日期 $d_i$ 以及他需要为该考试准备的天数 $p_i$。对于每次探险,Johnny 都知道它的开始日期 $s_j$ 和结束日期 $t_j$(包含首尾两天)。在任何探险期间,都不会有考试。Johnny 的记忆力很好,所以他可以在任何一天为任何考试做准备,但他每天只能为一场考试做准备。如果 Johnny 没有为某场考试做准备,他就不打算参加该考试。Johnny 不会在考试当天为考试做准备。所有考试都在不同的日期进行。

请帮助 Johnny 找出他最多能准备的考试数量。

输入格式

输入文件包含多组测试数据。

每组测试数据的第一行包含一个整数 $n$ ($1 \le n \le 10^5$)。接下来的 $n$ 行,每行包含两个整数:$d_i$ 和 $p_i$ ($0 \le p_i \le 10^9$, $1 \le d_i \le 10^{18}$)。接下来的行包含一个整数 $m$ ($0 \le m \le 10^5$)。接下来的 $m$ 行,每行包含两个整数:$s_j$ 和 $t_j$ ($1 \le s_j \le t_j \le 10^{18}$)。

最后一组测试数据后会跟一个零,该行不应被处理。

所有测试数据中 $n$ 的总和不超过 $10^5$。所有测试数据中 $m$ 的总和不超过 $10^5$。

输出格式

对于每组测试数据,输出两行。第一行包含 $k$ —— Johnny 最多能准备的考试数量。第二行包含 $k$ 个整数:这些考试的编号。考试编号按照它们在输入中出现的顺序从 1 到 $n$。

如果存在多个最优解,输出其中任意一个即可。

样例

输入 1

3
4 2
10 3
13 4
1
5 8
0

输出 1

2
1 3

说明 1

在给出的样例中,Johnny 可以例如在第 1 天和第 3 天为考试 1 做准备,并在第 2、9、10 和 11 天为考试 3 做准备。第 4 天和第 13 天用于考试,第 5 到 8 天用于探险。

Figure 1. 样例 1

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.