Language: Java

import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    long N=scan.nextLong();
    long K=scan.nextLong();
    long R=scan.nextLong();
    long S=scan.nextLong();
    long P=scan.nextLong();
    scan.nextLine();
    String[] T=scan.nextLine().split("");
    String[] before=new String[N];
    long count=0;
    for(long i=0;i<N;i++){
      if(i-K<0){
        if(T[i].equals("r")){
          before[i]="p";
          count+=P;
        }
        else if(T[i].equals("s")){
          before[i]="r";
          count+=R;
        }
        else if(T[i].equals("p")){
          before[i]="s";
          count+=S;
        }
      }
      else{
        if(T[i].equals("r")){
          if(before[i-K].equals("p")){
            before[i]="r";
            count+=0;
          }else{
            before[i]="p";
            count+=P;
          }
        }
        if(T[i].equals("p")){
          if(before[i-K].equals("s")){
            before[i]="p";
            count+=0;
          }else{
            before[i]="s";
            count+=S;
          }
        }
        if(T[i].equals("s")){
          if(before[i-K].equals("r")){
            before[i]="s";
            count+=0;
          }else{
            before[i]="r";
            count+=R;
          }
        }
      }
    }
    System.out.println(count);
  }
}

Compiler output:
Main.java:12: error: incompatible types: possible lossy conversion from long to int
    String[] before=new String[N];
                               ^
Main.java:16: error: incompatible types: possible lossy conversion from long to int
        if(T[i].equals("r")){
             ^
Main.java:17: error: incompatible types: possible lossy conversion from long to int
          before[i]="p";
                 ^
Main.java:20: error: incompatible types: possible lossy conversion from long to int
        else if(T[i].equals("s")){
                  ^
Main.java:21: error: incompatible types: possible lossy conversion from long to int
          before[i]="r";
                 ^
Main.java:24: error: incompatible types: possible lossy conversion from long to int
        else if(T[i].equals("p")){
                  ^
Main.java:25: error: incompatible types: possible lossy conversion from long to int
          before[i]="s";
                 ^
Main.java:30: error: incompatible types: possible lossy conversion from long to int
        if(T[i].equals("r")){
             ^
Main.java:31: error: incompatible types: possible lossy conversion from long to int
          if(before[i-K].equals("p")){
                     ^
Main.java:32: error: incompatible types: possible lossy conversion from long to int
            before[i]="r";
                   ^
Main.java:35: error: incompatible types: possible lossy conversion from long to int
            before[i]="p";
                   ^
Main.java:39: error: incompatible types: possible lossy conversion from long to int
        if(T[i].equals("p")){
             ^
Main.java:40: error: incompatible types: possible lossy conversion from long to int
          if(before[i-K].equals("s")){
                     ^
Main.java:41: error: incompatible types: possible lossy conversion from long to int
            before[i]="p";
                   ^
Main.java:44: error: incompatible types: possible lossy conversion from long to int
            before[i]="s";
                   ^
Main.java:48: error: incompatible types: possible lossy conversion from long to int
        if(T[i].equals("s")){
             ^
Main.java:49: error: incompatible types: possible lossy conversion from long to int
          if(before[i-K].equals("r")){
                     ^
Main.java:50: error: incompatible types: possible lossy conversion from long to int
            before[i]="s";
                   ^
Main.java:53: error: incompatible types: possible lossy conversion from long to int
            before[i]="r";
                   ^
19 errors