Not Able to understand why still the submission is failing? (LECANDY)

https://www.codechef.com/problems/LECANDY
Please help here where I went wrong, i tried testing using many cases, its giving correct output.

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
{
// your code goes here
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String nos = br.readLine();
if (null != nos) {
int n = Integer.parseInt(nos);
int sum = 0;
while (n > 0) {
String abc = br.readLine();
String[] a = abc.split(" “);
if (a.length > 0) {
int elephants = Integer.parseInt(a[0]);
int candies = Integer.parseInt(a[1]);
String numbers = br.readLine();
String[] number = numbers.split(” ");
int aa[] = new int[number.length];
for (int i = 0; i < aa.length; i++) {
aa[i] = Integer.parseInt(number[i]);
sum = sum + aa[i];
if (sum > candies) {
System.out.println(“No”);
System.exit(0);
}
}
} else {
System.out.println(“No”);
}
System.out.println(“Yes”);
n = n - 1;
}
}
}
catch(Exception e){
e.printStackTrace();
}
}
}

Please either format your code or link to your submission - the forum software has mangled it and it won’t compile!

Edit:

Consider the testcase:

2                     
10 1000000000
1 2 3 4 5 6 7 8 9 10
5 105 
10 10 10 10 11
1 Like

Thanks for the help actually variable sum was still carrying the sum of the previous no. of chocolate was being referred in the next cases too and because of which sum went equal to or lesser than 105. Right now I have submitted by modifying the variable sum, please advice how you considered this particular corner case ?
https://www.codechef.com/viewsolution/26844769

1 Like

I just read the code, eventually(!) spotted that you weren’t resetting sum for each testcase, and crafted a test input to expose this (the 105 is chosen specifically as it is one less than the sum of elephants across both testcases).