can anyone check the logic and say where am i going wrong???
================here is my code===================
https://www.codechef.com/viewsolution/22036469
thanx in advance!!!
Why are you using the value of an uninitialised variable n in Line 9 (memset)?
Edit -> Whoops! Found the bug!
From what I understood from going through your code, you are first checking what the remainder is upon division by 4.
Now, if the remainder is 0, we can solve the entire question in chunks of 4.
If the remainder is 1, we can the question in chunks of 4 and the last one in chunks of 5. (But we have to be careful not to use up the last chunk of 4 or else we’ll be left with a single element). I see that you handled that case well.
And so on, just preserving the last 5 or 6 or 7 elements.
Now, the problem arises when the remainder is 0. Since the last block of 4 is never used in the while loop (as it could lead to the isolation of 1 or 2 or 3 elements), therefore in the case of remainder 0 too, the last block of 4 is not used. So we need to fill the last block manually again. (Or you can just relax the conditions of the while loop when j==0.)
Here’s the link to your code which passes all the test cases!
yeah bro…jst figured it out…anyways thanx for such a quick reply…keep up the good work!!!