I have submitted the solution of this problem if july long challenge but it doesn't run in given time

please tell me how to optimise it further
link of my solution : https://www.codechef.com/viewsolution/36570327

for _ in range(int(input())):
h,p = map(int, input().split())
while h>0 and p != 0:
h = h-p
p = p/2

if p==0:
elif h<=0:

Try Pypy3, it runs faster. I myself ran it in PyPy3(your program), and it worked perfectly.

1 Like

Hey buddy!!
I have also done this problem with essentially same logic in Python 3 only.
I think you should try to define a function which does the same work as your code after reading input. I got right answer with that approach.

link to my code -> https://www.codechef.com/viewsolution/36438555

1 Like

@fallmount Instead of p=p/2 , use p=p//2
In p = p/2 python automatically converts it to floating point and in case when Chef dies p will keep on decreasing but will never become zero.
eg. testcase
1 10
In this p=p/2 will give

1 Like

@zacros you are right. That is the only difference between my and @fallmount code.
This is the reason why my code works fine but not his.
Thanks for pointing that out.
I really need to work on my skills to point out these things.

1 Like

I tried that but it gives wrong answer @zacros, if you don’t believe you can copy my code and change normal division to floor division and submit also you can see my submission with same changes here https://www.codechef.com/viewsolution/39778673. I have also tried @anon60151173 tip and it worked just submit the same code under pypy3 and it worked here is that submission https://www.codechef.com/viewsolution/39778660. At last thanks to all

Just exchange the last if else conditions. Elif one should come first. I did so with your code https://www.codechef.com/viewsolution/39787438 and it got accepted.