#ABC149D. Prediction and Restriction

Prediction and Restriction

题目描述

At an arcade, Takahashi is playing a game called RPS Battle, which is played as follows:

  • The player plays NN rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)
  • Each time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):
    • RR points for winning with Rock;
    • SS points for winning with Scissors;
    • PP points for winning with Paper.
  • However, in the ii-th round, the player cannot use the hand he/she used in the (iK)(i-K)-th round. (In the first KK rounds, the player can use any hand.)

Before the start of the game, the machine decides the hand it will play in each round. With supernatural power, Takahashi managed to read all of those hands.

The information Takahashi obtained is given as a string TT. If the ii-th character of TT (1iN)(1 \leq i \leq N) is r, the machine will play Rock in the ii-th round. Similarly, p and s stand for Paper and Scissors, respectively.

What is the maximum total score earned in the game by adequately choosing the hand to play in each round?

高桥(Takahashi)在一家游戏厅玩一款名为_RPS Battle_的游戏,游戏玩法如下:

  • 玩家与机器玩 NN 轮剪刀石头布。(有关 "剪刀石头布 "的说明,请参阅注释。平局也算一轮)。
  • 每次玩家赢一轮,根据他/她使用的手,他/她会获得以下分数(平局或输了不计分):
    • 用 "石头 "获胜得 RR 分;
    • 用剪刀获胜得 SS 分;
    • 用纸获胜得 PP 分。
  • 但是,在第 ii 轮中,玩家不能使用在第 (iK)(i-K) 轮中使用过的手牌。(在前 KK 轮中,玩家可以使用任何一手牌)。

游戏开始前,机器会决定每一轮的出牌方式。凭借超自然的力量,高桥成功地读取了所有这些手牌。

高桥获得的信息以 TT 字符串的形式给出。如果 TT 的第 ii 个字符 (1iN)(1 \leq i \leq N)TT 的话 (1iN)(1 \leq i \leq N)r,那么机器就会在第 ii 轮中出 Rock。同样,ps 分别代表 Paper(纸)和 Scissors(剪刀)。

如果在每一轮中都充分选择出牌,那么在游戏中获得的最高总分是多少?

输入格式

输入内容按以下格式标准输入:

NN KK
RR SS PP
TT

输出格式

打印游戏中获得的最高总分。

样例 #1

样例输入 #1

5 2
8 7 6
rsrpr

样例输出 #1

27

样例 #2

样例输入 #2

7 1
100 10 1
ssssppr

样例输出 #2

211

样例 #3

样例输入 #3

30 5
325 234 123
rspsspspsrpspsppprpsprpssprpsr

样例输出 #3

4996

说明

在这个问题中,"石头剪子布 "可以看作是一个双人游戏,每个玩家同时用一只手组成 "石头"、"剪子 "或 "布"。

  • 如果一方选择 "石头",另一方选择 "剪刀",则选择 "石头 "的一方获胜;
  • 如果一方选择 "剪刀",另一方选择 "纸",则选择 "剪刀 "的一方获胜;
  • 如果一方选择纸,另一方选择石头,则选择纸的一方获胜;
  • 如果双方都玩相同的牌,则平局。

数据规模与约定

  • 2N1052 \leq N \leq 10^5
  • 1KN11 \leq K \leq N-1
  • 1R,S,P1041 \leq R,S,P \leq 10^4
  • N,K,R,S,N,K,R,S,PP 都是整数。
  • T=N|T| = N
  • TTr, ps 组成。

样例 11 解释

机器将播放 {Rock, Scissors, Rock, Paper, Rock}.

例如,我们可以和它玩{纸、石头、石头、剪刀、布},从而获得 2727 分。我们无法获得更多的分数,因此答案为 2727