# 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

Please add comments in your code or explain your approach in detail for faster and effective response. 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

ok man all the best in the upcoming contests 