import sys from time import clock from array import array def main(): fin=open("in20_8.txt","r") start = clock() fout=open("out_28_20_8.txt","w") count=0 list=[] pie_wt=array('i') rack_wt=array('i') for x in fin: if count==0: list=x.split(" ") tst=int(list[0]) if count%3==1: list=x.split(" ") n=int(list[0]) if(n < 0 and n > 30): print(" Number of pies should be positive and not greater than 30") if count%3==2: pie_wt=[] list=x.split(" ") for i in range(0,n): pie_wt.append(int(list[i])) for i in range(0,n): if(pie_wt[i] < 0 or pie_wt[i]>100): print(" Weight of pie ",i+1," should be positive and less than 100") # Sorting the weights of pies pie_wt.sort() #print "pie wt",pie_wt if count%3==0 and count>0: rack_wt=[] list=x.split(" ") for i in range(0,n): rack_wt.append(int(list[i])) for i in range(0,n): if(rack_wt[i] < 0 or rack_wt[i] > 100): print(" Maximum Weight of rack ",i+1," should be positive and less than 100") # Sorting rack weights rack_wt.sort() #print "rack wt",rack_wt num = 0 j=0 for i in range(0,n): while (j < n and pie_wt[i] > rack_wt[j]): j=j+1 if (j < n): num=num+1 j=j+1 fout.write(str(num)) fout.write("\n") count=count+1 end = clock() time= end - start fout.write("\n Total execuion time ="+ str(time)+ " seconds") m=sys.getsizeof(list)+sys.getsizeof(rack_wt)+sys.getsizeof(pie_wt)+sys.getsizeof(num)+sys.getsizeof(n)+sys.getsizeof(fin)+sys.getsizeof(fout) fout.write("\n Memory used= "+str(m)+" bytes") fin.close() fout.close() main()