Advertisement
Alhiris

Untitled

Jan 9th, 2020
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. fin=open("in.in","r")
  2. fout=open("out.out","w")
  3. l=[]
  4. greutate=int(fin.readline())
  5. for i in fin:
  6.     aux=i.split()
  7.     t=tuple((len(l)+1,float(aux[0]),float(aux[1]),float(aux[1])/float(aux[0])))
  8.     l.append(t)
  9.  
  10. def keycomp(obicete):
  11.     return obiecte[3]
  12.  
  13. def alegere_pivot(l):
  14.     if len(l)<=5:
  15.         return sorted(l,key=keycomp)[len(l)//2]
  16.     subliste=[sorted(l[i:i+5]) for i in range(0,len(l),5)]
  17.     mediane=[sl[len(sl)//2] for sl in subliste]
  18.     return alegere_pivot(mediane)
  19.  
  20. def functie_principala(l,greutate,solutie):
  21.  
  22.     pivot=alegere_pivot(l)
  23.  
  24.     L=[x for x in l if x[3]<pivot[3]]
  25.     E=[x for x in l if x[3]==pivot[3]]
  26.     H=[x for x in l if x[3]>pivot[3]]
  27.  
  28.     if sum(ob[1] for ob in H)>greutate:
  29.         functie_principala(H,greutate,solutie)
  30.     else:
  31.         solutie+= [(*ob,1) for ob in H]
  32.         greutate-= sum(ob[1] for ob in H)
  33.         i=0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement