题库练习 Renovation
← 上一题 下一题 →

A11448 | Renovation

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

The mayor of the Berland city S sees the beauty differently than other city-dwellers. In particular, he does not understand at all, how antique houses can be nice-looking. So the mayor wants to demolish all ancient buildings in the city.

The city S is going to host the football championship very soon. In order to make the city beautiful, every month the Berland government provides mayor a money tranche. The money has to be spent on ancient buildings renovation.

There are $n$ months before the championship and the $i$ -th month tranche equals to $a_{i}$ burles. The city S has $m$ antique buildings and the renovation cost of the $j$ -th building is $b_{j}$ burles.

The mayor has his own plans for spending the money. As he doesn't like antique buildings he wants to demolish as much of them as possible. For the $j$ -th building he calculated its demolishing cost $p_{j}$ .

The mayor decided to act according to the following plan.

Each month he chooses several (possibly zero) of $m$ buildings to demolish in such a way that renovation cost of each of them separately is not greater than the money tranche $a_{i}$ of this month ( $b_{j}<=a_{i}$ ) — it will allow to deceive city-dwellers that exactly this building will be renovated.

Then the mayor has to demolish all selected buildings during the current month as otherwise the dwellers will realize the deception and the plan will fail. Definitely the total demolishing cost can not exceed amount of money the mayor currently has. The mayor is not obliged to spend all the money on demolishing. If some money is left, the mayor puts it to the bank account and can use it in any subsequent month. Moreover, at any month he may choose not to demolish any buildings at all (in this case all the tranche will remain untouched and will be saved in the bank).

Your task is to calculate the maximal number of buildings the mayor can demolish.

输入格式

The first line of the input contains two integers $n$ and $m$ $(1<=n,m<=100000)$ — the number of months before the championship and the number of ancient buildings in the city S.

The second line contains $n$ integers $a_{1},a_{2},...,a_{n}$ ( $1<=a_{i}<=10^{9}$ ), where $a_{i}$ is the tranche of the $i$ -th month.

The third line contains $m$ integers $b_{1},b_{2},...,b_{m}$ ( $1<=b_{j}<=10^{9}$ ), where $b_{j}$ is renovation cost of the $j$ -th building.

The fourth line contains $m$ integers $p_{1},p_{2},...,p_{m}$ ( $1<=p_{j}<=10^{9}$ ), where $p_{j}$ is the demolishing cost of the $j$ -th building.

输出格式

Output single integer — the maximal number of buildings the mayor can demolish.

输入输出样例

输入 #1
2 3
2 4
6 2 3
1 3 2
输出 #1
2
输入 #2
3 5
5 3 1
5 2 9 1 10
4 2 1 3 10
输出 #2
3
输入 #3
5 6
6 3 2 4 3
3 6 4 5 4 2
1 4 3 2 5 3
输出 #3
6
C++ 编辑器
输入
输出