TOWCNT - Editorial

@raja1999
In the tester’s code above . Can we initialise {max_num= -1, max_den=0} and {min_num = 1, min_den = 0} so that the initial max and min slopes are +infinite and -infinite respectively , and we don’t have to use the bools fl_max and fl_min because we will not be required to check with the (i+1)th element ??
This will shorten the code to a good extent.

I did everything as said, but still getting wa. I can’t see anything wrong in my code. Can somebody please help me?
https://www.codechef.com/viewsolution/32068228

How is the worst-case complexity 10 * (2000C2) if O(n^2) is the complexity and sum of n is 20,000.

complexity should have been 200 * 2000C2, isnt it?

Please help me…My solution is in python3 and its giving run time error when i submit it and i dont know why…I tried every possible testcase i could think of and getting correct output on my system. CodeChef: Practical coding for everyone
please check it once.

Total sum of all n over all test cases is 20000. So, the worst case is 10 test cases of 2000 each. Then, worst case time complexity would be 10*(2000C2).

Hey can I take it as a general case not to use double in these types of questions, as I know there is always some precision error and thus comparing things might not give consistent result, I was also stuck on spoj bcz of these things. So is it general thing that we keep them as fractions and not as double in questions like these?

I am getting WA. I used the solution as per the editorial. please help!
https://www.codechef.com/viewsolution/32112599

Thank you so much

Thanks for editorial! It really helped :slight_smile:

https://www.codechef.com/viewsolution/32112782
i used numerator and denominator. But why am i getting wrong answer help pls.

Can anyone please look into my code (CodeChef: Practical coding for everyone), it is giving correct answer of all the test cases I could think,but giving WA upon submission, or you can share some of the tricky test cases

@nqs_01 @rajarshi_basu I maintained slope in double and It worked fine!!!

You’ve initialised denominators to 0,I think they should be initialised to 1.

I have taken into consideration everything mentioned in editorial still getting Wrong Answer. Can anyone help me out ?
My Code

Did your code work after these suggestions ? I am doing almost same thing as you but still getting WA.

@meet_rv
Try this test case, you are doing same mistake as me, ignoring the bars on same x.
1
3 2
0 1 1
1 1 2

Output : 1 1

2 Likes

@abhaypatil2000
See Here

Summary

1
3 2
0 1 1
1 1 2
Ignoring bars at same x.

1 Like

can slope be negative in this quesion

Tried that also. Still it is giving Wrong Answer. Updated code NewCode. Still thanks for suggestion :slight_smile:

Edit: Got the issue. I wasn’t re-sorting them back according to id (realized this after seeing your code). Thank you!