You are not logged in. Please login at www.codechef.com to post your questions!

×

 0 import sys N = input() N=int(N) T= [] for i in range(0,N): i = input() i=i.split() T.append(i) T.append(i) Q=input() Q=int(Q) q=[] t=[] for j in range(0,Q): j=input() j=j.split() q.append(int(j)) temp=int(j) k=1 while(temp): t.append(int(j[k])) temp-=1 k+=1 temp=Q g=0 while(temp): count=0 a=[] for n in range(0,N): a.append(0) for m in range(0,q[Q-temp]): for o in range(0,N): if(int(T[2*o])<=t[g]): if(int(T[(2*o)+1])>=t[g]): if(a[o]==0): a[o]=1 count+=1 g+=1 print(count) temp-=1 del q del t del T del N  What can I do reduce my compile Time, pls suggest...i a beginner to python asked 30 Jun '12, 22:31 1●2●2●2 accept rate: 0% 0★admin ♦♦ 19.8k●350●498●541

 0 hiii, sachin answered 08 Apr '16, 15:04 1 accept rate: 0%
 0 It' NOT compile time, but runtime time. Simply your algorithm is slow. You are using three for loops, so the complexity of the algorithm is something like O(N*q[Q-1]), so for N = 10^5 and q[Q-1] = 10^9 it will run for 10^5 seconds - that's why you are getting TLE... answered 02 Jul '12, 15:41 16.9k●49●115●225 accept rate: 11%
 toggle preview community wiki:
Preview

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×529
×205
×19
×8

question asked: 30 Jun '12, 22:31

question was seen: 1,338 times

last updated: 08 Apr '16, 15:04