CF922E.Birds

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Apart from plush toys, Imp is a huge fan of little yellow birds!

To summon birds, Imp needs strong magic. There are nn trees in a row on an alley in a park, there is a nest on each of the trees. In the ii -th nest there are cic_{i} birds; to summon one bird from this nest Imp needs to stay under this tree and it costs him costicost_{i} points of mana. However, for each bird summoned, Imp increases his mana capacity by BB points. Imp summons birds one by one, he can summon any number from 00 to cic_{i} birds from the ii -th nest.

Initially Imp stands under the first tree and has WW points of mana, and his mana capacity equals WW as well. He can only go forward, and each time he moves from a tree to the next one, he restores XX points of mana (but it can't exceed his current mana capacity). Moving only forward, what is the maximum number of birds Imp can summon?

输入格式

The first line contains four integers nn , WW , BB , XX ( 1<=n<=103,0<=W,B,X<=1091<=n<=10^{3},0<=W,B,X<=10^{9} ) — the number of trees, the initial points of mana, the number of points the mana capacity increases after a bird is summoned, and the number of points restored when Imp moves from a tree to the next one.

The second line contains nn integers c1,c2,...,cnc_{1},c_{2},...,c_{n} ( 0<=ci<=1040<=c_{i}<=10^{4} ) — where cic_{i} is the number of birds living in the ii -th nest. It is guaranteed that .

The third line contains nn integers cost1,cost2,...,costncost_{1},cost_{2},...,cost_{n} ( 0<=costi<=1090<=cost_{i}<=10^{9} ), where costicost_{i} is the mana cost to summon a bird from the ii -th nest.

输出格式

Print a single integer — the maximum number of birds Imp can summon.

输入输出样例

  • 输入#1

    2 12 0 4
    3 4
    4 2
    

    输出#1

    6
    
  • 输入#2

    4 1000 10 35
    1 2 4 5
    1000 500 250 200
    

    输出#2

    5
    
  • 输入#3

    2 10 7 11
    2 10
    6 1
    

    输出#3

    11
    

说明/提示

In the first sample base amount of Imp's mana is equal to 1212 (with maximum capacity also equal to 1212 ). After he summons two birds from the first nest, he loses 88 mana points, although his maximum capacity will not increase (since B=0B=0 ). After this step his mana will be 44 of 1212 ; during the move you will replenish 44 mana points, and hence own 88 mana out of 1212 possible. Now it's optimal to take 44 birds from the second nest and spend 88 mana. The final answer will be — 66 .

In the second sample the base amount of mana is equal to 10001000 . The right choice will be to simply pick all birds from the last nest. Note that Imp's mana doesn't restore while moving because it's initially full.

首页