to Pay Respects

시간 제한1초메모리 제한1024 MB

요약
매 라운드 재생을 얻는 보스에게 독을 최대 K번 사용해 N라운드 동안 총 피해량을 최대로 만든다.
난이도

보통10점 중 7점

유형
그리디, 동적 계획법, 누적 합
정답자
아직 제출이 없습니다

문제

You are playing a game, and you are going to fight the secret boss. In this game, the boss doesn't 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, which means that the current state of the boss can be described with three integers: current health points (hphp), current poison stacks (pp) and current regeneration stacks (rr). At the beginning of the fight, there are no poison stacks and no regeneration stacks (p=r=0p=r=0). Each poison stack deals PP damage, each regeneration stack heals RR health points.

Spells have the following effects:

"Regeneration": increase the number of regenerations stacks rr by 11.

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

After the round the hphp will decrease 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 if the boss will cast "Regeneration". You have enough mana to cast "Poison" KK times (you don't have to use all of your mana). What's the largest total damage you can deal to the boss, in other words, what is the maximum value of hp_start−hp_endhp\_{start} - hp\_{end}? Assume that hp_start=101000hp\_{start} = 10^{1000}, so you can't actually kill the boss in NN rounds. Boss hphp can go higher than the initial value (see the third sample case).

입력

The first line of the input contains 55 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 of the input contains a binary string of length NN. The ii-th character of this string is 1, if the boss casts "Regeneration" at the beginning of the ii-th round, and 0 otherwise.

출력

Output a single integer --- the largest total damage you can deal during the fight.

힌트

Let's look at the first sample. We can cast the "Poison" spell at most once. Let's look at what will happen if we cast this spell during the first round.

  • During the first round, we apply a "Poison" spell, so at the end of this round there will be 00 regeneration stacks, and 11 poison stack. Therefore, the hphp will decrease by X+P⋅1−R⋅0=1011X + P\cdot 1 - R\cdot 0 = 1011 this round.
  • At the beginning of the second round, the boss will cast the "Regeneration" spell, so there will be 11 regeneration stack and 11 poison stack at the end of the second round. So, the hphp will decrease by X+P⋅1−R⋅1=1010X + P\cdot 1 - R\cdot 1 = 1010 this round. Overall, the health of the boss decreased by 1011+1010=20211011 + 1010 = 2021.

Now let's look at what will happen if we cast this spell during the second round.

  • During the first round, no spells are applied, so at the end of this round there will be 00 regeneration stacks, and 00 poison stacks. Therefore, the hphp will decrease by X+P⋅0−R⋅0=1010X + P\cdot 0 - R\cdot 0 = 1010 this round.
  • At the beginning of the second round, the boss will cast the "Regeneration" spell, so that there will be one regeneration stack after that. Then, we will we apply a "Poison" spell, decreasing the number of regeneration stacks by one. So, there will be 00 regeneration stacks and 11 poison stack at the end of the second round. Therefore, the hphp will decrease by X+P⋅1−R⋅0=1011X + P\cdot 1 - R\cdot 0 = 1011 this round. Overall, the health of the boss decreased by 1010+1011=20211010 + 1011 = 2021 again.

So, no matter when we cast the "Poison" spell in this sample, we will still decrease the hphp by 20212021.

예제3

  1. 예제 1

    입력
    2 1010 1 1 1
    01
    
    예상 출력
    2021
    
  2. 예제 2

    입력
    3 2 1 1 1
    001
    
    예상 출력
    8
    
  3. 예제 3

    입력
    10 1 10 40 1
    1111111111
    
    예상 출력
    -40