Calvin's Game problem

Why am i getting wrong answer???

import java.util.Scanner;

public class Main {
public static void main(String argrs[]){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int k=sc.nextInt();
int a[]=new int[n];
long dp[]=new long[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
dp[0]=a[0];
dp[1]=a[0]+a[1];
for(int i=2;i<n;i++){
dp[i]=Math.max(dp[i-1],dp[i-2])+a[i];
}

    /*for(int i=0;i<n;i++){
        System.out.print(dp[i]+" ");
    }
    System.out.println();*/
    if(k==1 && dp[n-1]<0)
        System.out.println(0);
    else
    System.out.println(2*dp[n-1]-dp[k-1]-a[n-1]);

}

}

Think of the following way:

We know that we must start from the position k. So, if we move in forward direction then for any i(>=k ans <n) calculate the max score and store in dp1[i].

Now for every i from 0 to n calculate the max score when traversed in reverse direction ans store in dp2[i]. Basically, dp2[i] should score the max score when we go from i to 0 in reverse direction.

Now, run a loop from k-1 to n (0- based indexing) and add dp1[i]+dp2[i]-a[i] to the answer.