Under construction

Still being built. Things may change

to Pay Respects

Time limit1sMemory limit1024 MB

Summary
Given a boss fight with regeneration and poison spells, find the maximum total damage when at most K poison casts are allowed.
Level

Hard8 of 10

Topics
Dynamic programming, Binary search, Greedy
Solved
No attempts yet

Statement

You are playing a game, and you are going to fight the secret boss. In this game, the boss does not attack you, but they can cast regeneration spells.

The fight consists of exactly NN rounds. In each round, the following actions can happen, in this order:

  1. The boss can choose to cast the "Regeneration" spell.
  2. You can choose to cast the "Poison" spell if you have any mana left.
  3. You attack with a sword, dealing XX damage.
  4. All the passive effects are applied.

There are two types of passive effects: regeneration and poison. The effects stack, so the state of the boss is described by three integers: current health hphp, current poison stacks pp, and current regeneration stacks rr. At the start of the fight, there are no poison stacks and no regeneration stacks (p=r=0p=r=0). Each poison stack deals PP damage, and each regeneration stack heals RR health points.

The spells have the following effects:

"Regeneration": increases the number of regeneration stacks rr by 11.

"Poison": increases the number of poison stacks pp by 11. If the number of regeneration stacks is strictly positive (r>0r > 0), it decreases rr by 11.

After each round, hphp decreases by X+P⋅p−R⋅rX + P \cdot p - R \cdot r. This value can be negative if the boss heals faster than you deal damage.

For each round, you know whether the boss casts "Regeneration". You have enough mana to cast "Poison" KK times, and you do not have to use all of it. What is the largest total damage you can deal to the boss? In other words, find the maximum value of hpstart−hpendhp_{start} - hp_{end}. Assume hpstart=101000hp_{start} = 10^{1000}, so you cannot actually kill the boss in NN rounds. The boss health can rise above the initial value (see the third sample).

Input

The first line contains five integers NN, XX, RR, PP, KK (1≤N,X,R,P≤1061 \le N, X, R, P \le 10^6, 0≤K≤N0 \le K \le N).

The second line contains a binary string of length NN. The ii-th character is 1 if the boss casts "Regeneration" at the beginning of the ii-th round, and 0 otherwise.

Output

Output one integer: the largest total damage you can deal during the fight.

Hint

Consider the first sample. You can cast "Poison" at most once. If you cast it in the first round, the boss loses X+P⋅1−R⋅0=1011X + P \cdot 1 - R \cdot 0 = 1011 health in that round, then X+P⋅1−R⋅1=1010X + P \cdot 1 - R \cdot 1 = 1010 in the second round, for a total of 2021. If you cast it in the second round, the boss loses 1010 in the first round and X+P⋅1−R⋅0=1011X + P \cdot 1 - R \cdot 0 = 1011 in the second round, which is also 2021. So the answer is 2021 either way.

Examples3

  1. Example 1

    Input
    2 1010 1 1 1
    01
    
    Expected output
    2021
    
  2. Example 2

    Input
    3 2 1 1 1
    001
    
    Expected output
    8
    
  3. Example 3

    Input
    10 1 10 40 1
    1111111111
    
    Expected output
    -40