Partial right answer

I don’t know why my code for the problem https://www.codechef.com/problems/EGRANDR
is giving partially correct answer .Please help me .My code :https://ideone.com/HmkDrP .
Thanks in advance.

You are breaking out of input-taking loop on encountering a “2”. Dont do that! Take the leftover input as well, else it messes up your code since its not able to take fiture input correctly.

1 Like

Adding to @vijju123 's answer , you can use a flag variable to denote that this case has failed and determine the output later after taking all inputs .

Here is the modified version of your code : https://ideone.com/8ZmW2M . I submitted it, and result is AC.

Mistakes in your code :
When you have multiple cases inside a single test-case, it’s better to avoid using “break”. Yes, with small input itself you may conclude an answer, but if you break input it there itself, when you consider input for next case, you will be getting input of previous case itself i.e.next point from where you stopped taking input.

(float)(sum/N)<4.0; during it’s evaluation, since sum and N both are integers, sum/N is also an integer, so when you cast it to float, you’re casting integer to float, which in situation is not what you’re trying to do.

Also, avoid comparison with floats, instead of (float(sum)/N)<4.0, better is (sum<(4*N)).

What is partial correct answer means when anyone is getting correct output for any solution ?

It works for some cases, and not for others.