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 approach for the problem ::

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

alt text

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:

alt text

Now , I came up with this equation
alt text

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

Please add comments in your code or explain your approach in detail for faster and effective response. :slight_smile:

Remove “community wiki” from your post or you won’t receive karma and so that next time you can create your own thread

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

thanks nilesh for your help.
Nilesh naam ke log coding me smart hote hai , it seems.

thanks harry potter . I tried this one but made mistake pointed by nilesh in the above comment.

ok man all the best in the upcoming contests :stuck_out_tongue: