QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 1024 MB 總分: 100

#5592. 家庭访问

统计

你是一名独自生活的大学生。然而,你那溺爱你的家人仍然喜欢来看望你,他们经常在晚上去吃晚饭前顺道检查你的房间。如果他们发现你的房间很乱,他们会很担心。因此,你努力确保他们在晚上来访时,你的房间永远不会显得杂乱。你每天下午都有一些空闲时间可以用来打扫,但由于之前的安排,每天的空闲时间各不相同。

幸运的是,你的日程安排得很周密。你确切地知道每天早上会制造多少垃圾,每天下午能清理多少垃圾,以及你的家人会在哪些晚上顺道拜访。由于你很懒,你希望尽可能少花几个下午的时间来打扫,以确保你的家人看到的房间永远不会有任何杂乱。你可以假设你的房间开始时是完全干净的,并且任何未清理的垃圾都会一直保留,直到被清理为止。

输入格式

输入的第一行包含两个整数 $n$ 和 $d$ ($1 \le d \le n \le 1\,000$),其中 $n$ 是你日程安排中的天数,$d$ 是你家人来访的天数。

接下来的 $n$ 行,每行包含两个整数 $m$ 和 $c$ ($0 \le m, c \le 1\,000$)。对于每一天,按顺序,$m$ 是你早上制造的垃圾量,$c$ 是你下午可以清理的垃圾量。

接下来的 $d$ 行,每行包含一个整数 $v$ ($1 \le v \le n$)。这些是你家人来访的日子,它们按严格递增的顺序排列。

输出格式

输出你必须花费的最少下午打扫次数,以确保你的家人永远不会看到杂乱的房间。如果无法做到,输出 $-1$。

样例

输入 1

6 2
1 2
2 1
1 4
3 2
3 6
2 3
3
6

输出 1

3

输入 2

10 5
12 10
0 2
7 1
1 8
3 4
3 4
2 3
1 2
10 1
7 5
2
4
5
6
8

输出 2

7

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.