Problem: At an arcade, Takahashi is playing a game called _RPS Battle_ , which is played as follows:    * The player 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 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):     * R points for winning with Rock;     * S points for winning with Scissors;     * P points for winning with Paper.   * However, in the i-th round, the player cannot use the hand he/she used in the (i-K)-th round. (In the first K 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 T. If the i-th character of T (1 \leq i \leq N) is `r`, the machine will play Rock in the i-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?

Submission attempts (in order):
N, K = map(int, input().split())
R, S, P = map(int,input().split())
T = input()
ans = 0
jr = [0]*N
js = [0]*N
jp = [0]*N
if T[0] == 'r':
  ans += R
  jr[0] = 1
elif T[0] =='s':
  ans += S
  js[0] = 1
else:
  ans += P
  jp[0] = 1
for i in range(1,N):
  if i < K:
    if T[i] == 'r':
      jr[i] = 1
      ans += R
    elif T[i] == 's':
      js[i] = 1
      ans += S
    else:
      jp[i] = 1
      ans += P
      
  elif i + K < N:
    if T[i] == 'r':
      if jr[i-K] == 0:
        jr[i] = 1
        ans += R
        
    elif T[i] == 's':
      if js[i-K] == 0:
        js[i] = 1
        ans += S
    
    elif T[i] == 'p':
      if jp[i-K] == 0:
        jp[i] = 1
        ans += P
  else:
    if T[i] == 'r':
      if jr[i-K] == 0:
        jr[i] = 1
        ans += R
        
    elif T[i] == 's':
      if js[i-K] == 0:
        js[i] = 1
        ans += S
        
    elif T[i] == 'p':
      if jp[i-K] == 1:
        jp[i] = 1
        ans += P
        
        
print(ans)
    
      


N, K = map(int, input().split())
R, S, P = map(int,input().split())
T = input()
ans = 0
jr = [0]*N
js = [0]*N
jp = [0]*N
if T[0] == 'r':
  ans += R
  jr[0] = 1
elif T[0] =='s':
  ans += S
  js[0] = 1
else:
  ans += P
  jp[0] = 1
for i in range(1,N):
  if i < K:
    if T[i] == 'r':
      jr[i] = 1
      ans += R
    elif T[i] == 's':
      js[i] = 1
      ans += S
    else:
      jp[i] = 1
      ans += P
      
  elif i + K < N:
    if T[i] == 'r':
      if jr[i-K] == 0:
        jr[i] = 1
        ans += R
        
    elif T[i] == 's':
      if js[i-K] == 0:
        js[i] = 1
        ans += S
    
    elif T[i] == 'p':
      if jp[i-K] == 0:
        jp[i] = 1
        ans += P
  else:
    if T[i] == 'r':
      if jr[i-K] == 0:
        jr[i] = 1
        ans += R
        
    elif T[i] == 's':
      if js[i-K] == 0:
        js[i] = 1
        ans += S
        
    elif T[i] == 'p':
      if jp[i-K] == 0:
        jp[i] = 1
        ans += P
        
        
print(ans)
    
      


N, K = map(int, input().split())
R, S, P = map(int,input().split())
T = input()
ans = 0
jr = [0]*N
js = [0]*N
jp = [0]*N
if T[0] == 'r':
  ans += R
  jr[0] = 1
elif T[0] =='s':
  ans += S
  js[0] = 1
else:
  ans += P
  jp[0] = 1
for i in range(1,N):
  if i < K:
    if T[i] == 'r':
      jr[i] = 1
      ans += R
    elif T[i] == 's':
      js[i] = 1
      ans += S
    else:
      jp[i] = 1
      ans += P
      
  elif i + K < N:
    if T[i] == 'r':
      if jr[i-K] == 0:
        jr[i] = 1
        ans += R
      else:
        if T[i + K] == 'p':
          js[i] = 1
        else:
          jp[i] = 1
    elif T[i] == 's':
      if js[i-K] == 0:
        js[i] = 1
        ans += S
      else:
        if T[i+K] == 'r':
          jp[i] = 1
        else:
          jr[i] = 1
    elif T[i] == 'p':
      if jp[i-K] == 1:
        jp[i] = 1
        ans += P
      else:
        if T[i + K] == 's':
          jr[i] = 1
        else:
          js[i] = 1
  else:
    if T[i] == 'r':
      if jr[i-K] == 0:
        jr[i] = 1
        ans += R
    elif T[i] == 's':
      if js[i-K] == 0:
        js[i] = 1
        ans += S
    elif T[i] == 'p':
      if jp[i-K] == 1:
        jp[i] = 1
        ans += P
        
        
print(ans)
    
      

N, K = map(int, input().split())
R, S, P = map(int,input().split())
T = input()
ans = 0
jr = [0]*N
js = [0]*N
jp = [0]*N
if T[0] == 'r':
  ans += P
  jr[0] = 1
elif T[0] =='s':
  ans += R
  js[0] = 1
else:
  ans += S
  jp[0] = 1
for i in range(1,N):
  if i < K:
    if T[i] == 'r':
      jr[i] = 1
      ans += P
    elif T[i] == 's':
      js[i] = 1
      ans += R
    else:
      jp[i] = 1
      ans += S
      
  elif i + K < N:
    if T[i] == 'r':
      if jr[i-K] == 0:
        jr[i] = 1
        ans += P
        
    elif T[i] == 's':
      if js[i-K] == 0:
        js[i] = 1
        ans += R
    
    elif T[i] == 'p':
      if jp[i-K] == 0:
        jp[i] = 1
        ans += S
  else:
    if T[i] == 'r':
      if jr[i-K] == 0:
        jr[i] = 1
        ans += P
        
    elif T[i] == 's':
      if js[i-K] == 0:
        js[i] = 1
        ans += R
        
    elif T[i] == 'p':
      if jp[i-K] == 0:
        jp[i] = 1
        ans += S
        
        
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted