Please help https://www.codechef.com/problems/TWODOGS

My code is running in intellij but not in codechef.
my code----
import java.util.Arrays;
import java.util.Scanner;
import java.math.*;

class TWODOGS {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int K = sc.nextInt();
int[] AppleArray = new int[N];
for (int i = 0; i < N; i++) {
AppleArray[i] = sc.nextInt();
}
int a = 0;
int[] TimeArray = new int[N];
for (int k = 0; k < N; k++) {
for (int l = k+1; l < N; l++) {
if (AppleArray[k] + AppleArray[l] == K) {
TimeArray[a] = Math.max(Math.min(k + 1, N - k), Math.min(N - l, l + 1));
a++;
}
}
}
if (a == 0) {
System.out.println("-1");
} else {
int[] AnotherArray = new int[a];
for (int j = 0; j < a; j++) {
AnotherArray[j] = TimeArray[j];
}
Arrays.sort(AnotherArray);
System.out.println(AnotherArray[0]);
}
sc.close();
}
}