I am getting run time error in this code. This was the problem of September lunchtime. Sub task 1 is submitted successfully but in sub task it’s giving RE.
Please some one help me to identify the error
`import java.util.Scanner;
class FindTheSum {
long a[];
long dp[][];
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t>0){
FindTheSum o = new FindTheSum();
int N = sc.nextInt();
int Q = sc.nextInt();
o.a = new long[N];
o.dp= new long [N+1][N+1];
for(int i=1;i<=N-1;i++){
o.a[i] = sc.nextLong();
}
int x,y;
for(int i=1;i<=Q;i++){
x = sc.nextInt();
y = sc.nextInt();
int max = Math.max(x, y);
int min = Math.min(x,y);
x = min; y = max;
long ans = o.getValue(x, y);
if(ans!=-1){
o.dp[x][y] = ans;
System.out.println(ans);
}
}
t--;
}
}
private long getValue(int x, int y) {
if(x-y==1||y-x==1){
return a[y-1];
}
else if((x%2==0&&y%2==0)||(x%2!=0&&y%2!=0)){
System.out.println("UNKNOWN");
return -1;
}
else if(x%2==0||x%2!=0){
if(dp[x][y-2]!=0){
return dp[x][y-2]+a[y-1]-a[y-2];
}
return getValue(x,y-2)+a[y-1]-a[y-2];
}
return 0;
}
}
`