# facing problem when submittin Solution of "Paying up" problem link below, giving WA to mySolution

/*
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
//package LearntLogicWhichDontKnow;

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();

}
ArrayList<Integer> al = new ArrayList<>(noOfCoins);
for (int p = 0; p < noOfCoins; p++) {
}
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.set(count, 1);
return check(al, count) + check(newal, count);
}
}

please help me to ping out what is problem with my code that codechef compiler is giving WA… i think my code should work for all test cases even it is working for given test cases

Dear, I highly suggest that you copy and run this code at “Code, Compile and Run” Section of Practice. (Because it will run your code on codechef IDE)

Because I tried running your code, and I got this error-

Error: Could not find or load main class MARCHA2

I think java programs have to abide by some syntax or so (will edit and add link once I find it) and that’s why I got that error. If you can fix it, I can try running for test cases.

EDIT- I found a tutorial for your Q incase you want to have a look Tutorial for Paying Up

EDIT2- Dear, I am getting new set of errors on running program,

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)

Try running it yourself.

i solved why my solution giving WA besides having right logics because “YES” And “NO” should be “Yes” and “No”… now submitted againg and solution acceted and right answer

There dear-

before this package name was not commented… now i comment the packagename… may be that is causing problem… now u can try

Thanks dear, I will start testing (BTW, did u try re-submitting soln. ? In case this error was giving you WA? )

EDIT- New set of errors-

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)

I recommend using Buffered Reader to fix it. Try that.

Because codechef wants you to use buffered reader. Things vary from one online compiler to other. That’s why I requested for buffered reader dear

And m glad you found out. Yes, you must be careful for the output format!! Many , MANY times it just makes you pull your hair out of frustration thinking “Where did my code went wrong in logic” while its just a simple typo. Glad you found it out!

than dear, why codechef ide accepted my solution using Scanner, i havn’t used bufferReader

Lol, now even code compile run is accepting it XD

even now its not compile right for my solution… can send me ur screenshot!

lol… okey now i got it. earlier we are not providing any custom input and trying to run our code… no compiler is able to provide us output without input… thanx bro… u helped me alot

Dear, when I ran it initially I WAS providing it input and it was actually not detecting it for some reason. It seems to be fixed now (created a new tab of IDE).

I am glad dear I was of help and that your problem is resolved.