Logo
(追記) (追記ここまで)

31151번 - to Pay Respects 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB32212064.516%

문제

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 $N$ 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 $X$ 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 ($hp$), current poison stacks ($p$) and current regeneration stacks ($r$). At the beginning of the fight, there are no poison stacks and no regeneration stacks ($p=r=0$). Each poison stack deals $P$ damage, each regeneration stack heals $R$ health points.

Spells have the following effects:

"Regeneration": increase the number of regenerations stacks $r$ by 1ドル$.

"Poison": increase the number of poison stacks $p$ by 1ドル$. If the number of regeneration stacks is strictly positive ($r > 0$), then decrease it by 1ドル$.

After the round the $hp$ will decrease by $X + 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" $K$ 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_{end}$? Assume that $hp_{start} = 10^{1000},ドル so you can't actually kill the boss in $N$ rounds. Boss $hp$ can go higher than the initial value (see the third sample case).

입력

The first line of the input contains 5ドル$ integers $N,ドル $X,ドル $R,ドル $P,ドル $K$ (1ドル \le N, X, R, P \le 10^6,ドル 0ドル \le K \le N$).

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

출력

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

제한

예제 입력 1

2 1010 1 1 1
01

예제 출력 1

2021

예제 입력 2

3 2 1 1 1
001

예제 출력 2

8

예제 입력 3

10 1 10 40 1
1111111111

예제 출력 3

-40

노트

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 0ドル$ regeneration stacks, and 1ドル$ poison stack. Therefore, the $hp$ will decrease by $X + 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 1ドル$ regeneration stack and 1ドル$ poison stack at the end of the second round. So, the $hp$ will decrease by $X + P\cdot 1 - R\cdot 1 = 1010$ this round. Overall, the health of the boss decreased by 1011ドル + 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 0ドル$ regeneration stacks, and 0ドル$ poison stacks. Therefore, the $hp$ will decrease by $X + 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 0ドル$ regeneration stacks and 1ドル$ poison stack at the end of the second round. Therefore, the $hp$ will decrease by $X + P\cdot 1 - R\cdot 0 = 1011$ this round. Overall, the health of the boss decreased by 1010ドル + 1011 = 2021$ again.

So, no matter when we cast the "Poison" spell in this sample, we will still decrease the $hp$ by 2021ドル$.

출처

Contest > Open Cup > 2021/2022 Season > Stage 7: Grand Prix of Southeastern Europe F번

ICPC > Regionals > Europe > Southeastern European Regional Contest > SEERC 2021 F번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /