Running the code gives ouput - java.util.NoSuchElementException. But in the case of custom input, it works fine. Where am I wrong? Can anyone help me?
/* package codechef; // don’t place package name! */
import java.util.;
import java.lang.;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
try
{
Scanner scan = new Scanner(System.in);
int tc = scan.nextInt();
for (int i = 0; i < tc; i++)
{
int n;
long qpd;
long day = 0;
long q = 0;
boolean flag = false;
n = scan.nextInt();
qpd = scan.nextLong();
long[] qpdl = new long[n];
for (int j = 0; j < n; j++) qpdl[j] = scan.nextLong();
for (int j = 0; j < n; j++)
{
day++;
qpdl[j] = qpdl[j] + q;
if (qpdl[j] < qpd)
{
System.out.println(day);
flag = true;
break;
}
else q = qpdl[j] - qpd;
}
if (!flag)
{
day += (q / qpd) + 1;
System.out.println(day);
}
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}