CF883J.Renovation

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

伯兰德城市 S 的市长对“美”的理解与其他市民截然不同。特别是,他完全无法理解古建筑为何会显得美观。因此,市长打算拆除该市所有古建筑。

足球锦标赛即将在城市 S 举办。为了使城市看起来更美,伯兰德政府每月向市长拨付一笔专项资金用于古建筑修缮。

距离锦标赛还有 nn 个月,第 ii 个月的拨款为 aia_i 卢布。城市 S 共有 mm 座古建筑,第 jj 座建筑的修缮费用为 bjb_j 卢布。

市长对资金使用另有规划。由于他不喜欢古建筑,他希望尽可能多地拆除它们。对于第 jj 座建筑,他已计算出其拆除费用为 pjp_j 卢布。

市长决定按如下方案执行:

每个月,他从这 mm 座建筑中选择若干座(可以为零座)进行拆除,要求:所选每座建筑的修缮费用均不超过当月拨款 aia_i(即满足 bj≤aib_j \leq a_i)——此举可欺骗市民,使其相信这些被选中的建筑将被修缮。

随后,市长必须在当月内拆除所有已选定的建筑;否则市民将识破骗局,整个计划将失败。当然,当月所选建筑的拆除总费用不得超过市长当前可动用的资金总额。市长无需将当月全部拨款都用于拆除;若有结余,他可将剩余资金存入银行账户,并在后续任意月份中使用。此外,在任一月份,市长也可选择不拆除任何建筑(此时整笔拨款将原封不动地存入银行)。

你的任务是:计算市长最多能拆除多少座建筑。

输入格式

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100 000) — 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 ≤ 109), 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 ≤ 109), 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 ≤ 109), where p__j is the demolishing cost of the j-th building.

输入的第一行包含两个整数 nn 和 mm(1≤n,m≤100 0001 \leq n, m \leq 100\,000)——分别表示锦标赛前的月份数和城市 S 中的古建筑数量。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091 \leq a_i \leq 10^9),其中 aia_i 表示第 ii 个月的拨款额。

第三行包含 mm 个整数 b1,b2,…,bmb_1, b_2, \dots, b_m(1≤bj≤1091 \leq b_j \leq 10^9),其中 bjb_j 表示第 jj 座建筑的翻新费用。

第四行包含 mm 个整数 p1,p2,…,pmp_1, p_2, \dots, p_m(1≤pj≤1091 \leq p_j \leq 10^9),其中 pjp_j 表示第 jj 座建筑的拆除费用。

输出格式

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

说明/提示

In the third example the mayor acts as follows.

In the first month he obtains 6 burles tranche and demolishes buildings #2 (renovation cost 6, demolishing cost 4) and #4 (renovation cost 5, demolishing cost 2). He spends all the money on it.

After getting the second month tranche of 3 burles, the mayor selects only building #1 (renovation cost 3, demolishing cost 1) for demolishing. As a result, he saves 2 burles for the next months.

In the third month he gets 2 burle tranche, but decides not to demolish any buildings at all. As a result, he has 2 + 2 = 4 burles in the bank.

This reserve will be spent on the fourth month together with the 4-th tranche for demolishing of houses #3 and #5 (renovation cost is 4 for each, demolishing costs are 3 and 5 correspondingly). After this month his budget is empty.

Finally, after getting the last tranche of 3 burles, the mayor demolishes building #6 (renovation cost 2, demolishing cost 3).

As it can be seen, he demolished all 6 buildings.

在第三个例子中,市长的操作如下:

第一个月,他获得 6 卢布的拨款,并拆除了第 2 号建筑(翻新费用为 6,拆除费用为 4)和第 4 号建筑(翻新费用为 5,拆除费用为 2)。他将全部资金用于此次拆除。

第二个月获得 3 卢布拨款后,市长仅选择拆除第 1 号建筑(翻新费用为 3,拆除费用为 1)。因此,他为后续月份节省了 2 卢布。

第三个月他获得 2 卢布拨款,但决定不拆除任何建筑。结果,他在银行中存有 2+2=42 + 2 = 4 卢布。

这笔储备金将在第四个月与当月的 4 卢布拨款一同使用,用于拆除第 3 号和第 5 号建筑(两者的翻新费用均为 4,拆除费用分别为 3 和 5)。该月结束后,他的预算归零。

最后,在获得最后一笔 3 卢布拨款后,市长拆除了第 6 号建筑(翻新费用为 2,拆除费用为 3)。

由此可见,他成功拆除了全部 6 座建筑。

输入解题思路,AI测评打分。不知道怎么写?

首页