i am getting time limit exceed in my program and i am not getting whats the problem the question is Please Like me
itr = int(raw_input())
arr = []
for i in xrange(0,itr):
inp = raw_input()
a , b , c , d = [int(d) for d in inp.split()]
for j in xrange(1 , b):
c= c + (c*d)
if c>=a:
e = "ALIVE AND KICKING"
else:
e = "DEAD AND ROTTING"
arr.append(e)
for i in xrange(0 ,itr):
print arr[i]
@dpmittal: you are getting TLE because you are iterating b times to calculate final c for every input. you are taking T*D computations to complete one test file and this will lead to TLE because T,D are very large and the time limit is 1sec in which you can compute 10^7 to 10^8 computations. you can optimize that to a very large extent by using basic maths.
The condition to be checked is:s((1+c)^d-1)>=l; this is the same condition you have used but to check this condition ,there is no need to find value of s((1+c)^d-1),which is the wrong you have commited.long long int can store up to 10^18 only but the left hand side value will be much more than that resulting in overflow which is the reason for your wrong answer ot tle. A simple implementation like this would suffice:
You need not print all the answers at a time. Means you need not store the answers in an array(in this case you are using arr[]). You can print them after checking for each case.
sorry for the above explanation, this logic is working in C but getting TLE in python. do one thing in your above mentioned code do not iterate from(1,b) stop iteration when ever you exceed āaā in your program and break the āforā loop because you need not iterate further if you got minimum number of likes. this will work you can view at my code which is coded on the basis of your logic CodeChef: Practical coding for everyone thank you donāt forget to accept my answer