QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 256 MB 總分: 100

#8439. 插座

统计

Valera 的公寓里只有一个电源插座。他还有 $m$ 个需要用电的设备。他有 $n$ 个排插,其中第 $i$ 个排插有 $a_i$ 个插孔。

一个设备或排插如果被直接插入电源插座,或者被插入到某个已经通电的排插中,它就能获得电力。

对于每个设备 $j$,Valera 知道它的安全值 $b_j$,这表示该设备与公寓电源插座之间的路径上允许经过的排插的最大数量。例如,如果 $b_j = 0$,则该设备必须直接插入公寓的电源插座中。

Valera 同时最多能为多少个设备供电?注意,所有设备和排插在插入时都会占用一个插孔,且每个插孔只能插入一个设备或一个排插。

输入格式

第一行包含两个空格分隔的整数 $n$ 和 $m$ ($1 \le n, m \le 2 \cdot 10^5$),分别表示排插的数量和设备的数量。

第二行包含 $n$ 个空格分隔的整数 $a_1, a_2, \dots, a_n$ ($2 \le a_i \le 2 \cdot 10^5$)。其中 $a_i$ 表示第 $i$ 个排插的插孔数量。

第三行包含 $m$ 个空格分隔的整数 $b_1, b_2, \dots, b_m$ ($0 \le b_j \le 2 \cdot 10^5$)。其中 $b_j$ 表示第 $j$ 个设备的安全值。

输出格式

输出一个整数:同时最多能供电的设备数量。

样例

样例输入 1

3 5
3 2 2
1 2 2 1 1

样例输出 1

4

样例输入 2

3 3
2 2 2
1 2 2

样例输出 2

3

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.