https://www.codechef.com/SDPCB21/submit/QUALPREL

plz check my code …i don’t know what’s wrong with my code (question= Covid Spread)

( COVSPRD)

t=int(input())

while(t>0):
n,d=map(int,input().split())
k=min(d,10)

a=1
for i in range(k):
    #print(i)
    a=a*2
    
#print(a)

if(d>10):
    for i in range (d-10):
        a=a*3
        
if(n>a):
    print(a)
else:
    print(n)

t-=1

Hi, you are getting TLE issue, which means you need to reduce the number of operation and that can be done in this loop:

if(d>10):
    for i in range (d-10):
        a=a*3

Here in this loop, when value of a(infected people on that day) becomes greater than n(total population) we can simply break out of the loop because the entire ChefLand is now infected and there’s no more people to infect so, any iteration after this will be useless.

1 Like

Your solution is not optimized and not according .Here is my solution for the problem.
You are calculating it unnecessarily.

Check My Solution