problem link
why when submitting My answer using Scanner it got accepted but when i tried codechef ide by Code, Compile and Run" Section of Practice… it is giving error as follow–
Exception in thread “main” java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076) at MARCHA2.main(Main.java:23)
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author Hemant Dhanuka
*/
class MARCHA2 {
static int totalAmount, noOfCoins;
static int[] coinValue;
static boolean exist = false;
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int noOfCases = s.nextInt();
for (int i = 0; i < noOfCases; i++) {
noOfCoins = s.nextInt();
totalAmount = s.nextInt();
coinValue = new int[noOfCoins];
for (int j = 0; j < noOfCoins; j++) {
coinValue[j] = s.nextInt();
}
//int[] booleanArray=new int[noOfCoins];
// Integer[] booleanArray=new Integer[noOfCoins];
// List<Integer> booleanArrayList = Arrays.stream(booleanArray).boxed().collect(Collectors.toList());
//ArrayList<Integer> booleanArrayList=new ArrayList<>(Arrays.asList(booleanArray));
ArrayList<Integer> al = new ArrayList<>(noOfCoins);
for (int p = 0; p < noOfCoins; p++) {
al.add(0);
}
exist = false;
check(al, -1);
if (exist) {
System.out.println("Yes");
} else {
System.out.println("No");
}
}
}
private static int check(ArrayList<Integer> al, int count) {
int sum = 0;
count++;
for (int i = 0; i < noOfCoins; i++) {
if (al.get(i) == 1) {
sum = sum + coinValue[i];
}
}
if (sum == totalAmount) {
exist = true;
return 0;
}
if (sum > totalAmount) {
return 0;
}
if (count == noOfCoins) {
return 0;
}
ArrayList<Integer> newal = new ArrayList<>();
for (int b = 0; b < al.size(); b++) {
newal.add(al.get(b));
}
newal.set(count, 1);
return check(al, count) + check(newal, count);
}
}