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

code
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:
    print(0)
elif h<=0:
    print(1)

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
1 10
In this p=p/2 will give
p=1
p=0.5
p=0.25


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