# Help in Chef goes to Cinema

March cook-off 2018
Here is the link of my code. IT is not working, ALTHOUGH THE APPROACH LOOKS PROMISING.
Please go through the code once

https://www.codechef.com/viewsolution/17898715

2 Likes

Your code was hard to understand but I guess the problem lies potential over flow at

``````int sum = mid * (mid + 1) / 2;
if (sum <= s && (mid+1)*(mid+2) >=2*s)
return mid;
``````

Ok there was one more mistake it should be â€śn+sumaâ€ť not â€śn+suma+1â€ť. Your AC submission.

I also misread the constraints and used binary search without generating array. You can refer to my solution, itâ€™s a bit cleaner than yours.

2 Likes

Here is my submission for the above problem ::
https://www.codechef.com/viewsolution/17906061

Here is my approach for the problem ::

I used Quadratic formula to check the exact decimal value of n

Here x represents an unknown, while a, b, and c are constants with a not equal to 0. One can verify that the quadratic formula satisfies the quadratic equation by inserting the former into the latter. With the above parameterization, the quadratic formula is:

Now , I came up with this equation

if the value of n received after this is integer , weâ€™ll print the ans else weâ€™ll check for the absolute difference between this value and the closest possible upper and lower bound values , then print the one with lowest difference .
Hope it helps , rest in the solution

1 Like

editorial has been added, have a look, here