Max sum k partition . Why getting wrong answer?

import java.util.Scanner;

public class Main {
public static void main(String argsp[]){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int k=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
long ind=0;
long ind_r=0;
long max1=0;
long max2=0;
long max11=0;
long max22=0;
long dp[]=new long[n];
for(int i=0;i<n;i++){

       if(i-ind_r!=k){
           dp[i]=a[i]+max11;
       }
       else
       {
           dp[i]=a[i]+max22;
       }
        if(dp[i]>max1) {
            max2=max1;
            max1 = dp[i];
            ind=i;

        }

        if((i+1)%k==0){
            max11=max1;
            max22=max2;
            ind_r=ind;
        }
        //System.out.print(dp[i]+" ");
    }
    if(ind-ind_r!=k)
        max11=max1;
    System.out.println(max11);
}

}

I am going to try and give you my logic, and the C++ code, but logic will be sufficient
assign dp[] = a[]
now for(i=k:n, i+=k)
u take a maxi = i-k to store the final best index in this window)
and smax = -1 (to store the final second best index in this window)
here best means index with max value
now for(int j = i - k + 1; j < i; j++):
if (dp[j] > dp[maxi]) that means a better index is found so update smax and maxi to maxi and j respectively
else if I find an element which is not max but greater than second max or second max is not assigned yet assign j to second max
end of loop of j
now for j=i:k
if(a[j] < 0) dp[j] = dp[max_i]; //for negative elements

        else if(j - max_i != k) dp[j] = a[j] + dp[max_i]; given condition 

        else dp[j] = a[j] + dp[smax_i]; if above is false we take this

        maxSum = max(maxSum, dp[j]); final answer

code: