2863: ABC149D - Prediction and Restriction
Memory Limit:128 MB
Time Limit:1.000 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Problem Statement
At an arcade, Takahashi is playing a game called RPS Battle, which is played as follows:-
The pla
yer plays N 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 pla
yer wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss): - R points for winning with Rock;
- S points for winning with Scissors;
- P points for winning with Paper.
-
However, in the ii-th round, the pla
yer cannot use the hand he/she used in the (i−K)-th round. (In the first K rounds, the player can use any hand.)
The information Takahashi obtained is given as a string TT. If the ii-th character of TT (1≤i≤N)(1≤i≤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?
Notes
In this problem, Rock Paper Scissors can be thought of as a two-pla-
If a pla
yer chooses Rock and the other chooses Scissors, the pla yer choosing Rock wins; -
if a pla
yer chooses Scissors and the other chooses Paper, the pla yer choosing Scissors wins; -
if a pla
yer chooses Paper and the other chooses Rock, the pla yer choosing Paper wins; -
if both pla
yers play the same hand, it is a draw.
Constraints
- 2≤N≤105
- 1≤K≤N−1
- 1≤R,S,P≤104
- N,K,R,S and P are all integers.
- |T|=N
- T consists of r, p, and s.
Input
Input
Input is given from Standard Input in the following format:
N K
R S P
T
Output
Output
Print the maximum total score earned in the game.Sample Input Copy
5 2
8 7 6
rsrpr
Sample Output Copy
27