Below is my code for problem with problem code : BUYING2, link: https://www.codechef.com/problems/BUYING2
it is giving me “wrong answer” on submission, while it is running smoothly on my pc, please help me out, I am new around here…
import java.util.Scanner;
class BUYING2 {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
while(T > 0) {
int Total = 0;
boolean flag = false;
int N = in.nextInt();
int X = in.nextInt();
int A[] = new int[N];
for(int i = 0; i < N; i++) {
A[i] = in.nextInt();
Total = Total + A[i];
}
int noOfSweets = Total / X;
for(int i = 0; i < N; i++) {
if((Total % X) - A[i] > 0) {
flag = true;
break;
}
}
if(flag == true)
System.out.println("-1");
else
System.out.println(noOfSweets);
T--;
}
in.close();
}
}