fork(1) download
  1. def findpro():
  2. p = [11, 21, 31, 33, 43, 53, 55, 65]
  3. w = [1, 11, 21, 23, 33, 43, 45, 55]
  4. maxw = 110
  5. a = map(lambda x: x[0]/x[1],zip(p,w))
  6. c = zip(a,range(len(a)))
  7. order = map(lambda x:x[1], sorted(c,reverse=True))
  8. profit = 0
  9. wt = maxw
  10. for i in range(len(order)):
  11. if(w[i]<=wt):
  12. if(wt>0):
  13. profit += p[i]
  14. wt = wt - w[i]
  15. print "p" ,profit, "w", wt
  16. else:
  17. if(wt>0):
  18. profit += ((maxw-w[i])/(w[i]))*p[i]
  19. wt = wt - w[i]
  20. print "p" ,profit, "w", wt
  21. print profit
  22.  
Success #stdin #stdout 0.01s 7724KB
stdin
Standard input is empty
stdout
Standard output is empty