wrong answer in snakeat


what i did was to simply find the number before query …and then do as below-

Suppose the numbers are {11, 12, 13, 14, 15, 16} , and suppose 16 is the query, then find out 15 by binary search (the no less than k).

Then i will have a total of 4 numbers left to eat up(11 12 13 14) so 15 eats one to get to 16 … So now left with 3 … 14 eats 2 so we are left with (3-2-1)…including 14 also gone thereby total number being 16,15,14 …

(EDIT- From Vijju123- Basically what hes trying to say is that snake no. 15 will eat one snake and be of length 16, and 14 will eat 2 snakes and become of length 16.)

it works for repetitive elements also…then where am I going wrong can anyone help please…?

Write full words.

1 Like

Explain your doubt better. Write in full words. This is not text.

An attempt to fix the grammar had been made.

Regards, Vijju123

There might still be some other conditions you are missing. Check for your conditions well.

I have the same question.MY code was working for all type of test cases that, I could think of but still i was getting the wrong answer after submission.

for(int j=0;j<q;j++){


In the above code, you used break statement which would take the control out of the loop which has been used for processing the queries. So the next queries will not be processed and it will give you WA.

Instead of the break statement, you should use continue statement so that it can process the next queries also.This will correct your program but it will give you TLE.
For the below Input :


2 2

5 7



The output of your program is :


Whereas the expected output should be :



1 Like

Please provide the link of your solution.


I can’t find anything wrong in it.

Plz help me find the bug. Appreciate it.

Thanks in advance.

Your solution does not seem to be of the problem SNAKEEAT.