fork download
  1. def parse(inFile):
  2. return (tuple(inFile.getInts()+[inFile.getInts()]))
  3.  
  4. def solve((N,W,L,rs)):
  5. xs = [(rs[i],i) for i in xrange(N)]
  6. xs.sort()
  7. coords = [(-1,-1) for i in xrange(N)]
  8. lhs = [(0,0),(0,L)]
  9. for (r,i) in xs[::-1]:
  10. for z in xrange(len(lhs)):
  11. m = lhs[z]
  12. if m[0] == 0 or (m[0] + r) <= W:
  13. cx = 0 if (m[0] == 0) else (m[0] + r)
  14. cy = 0 if (m[1] == 0) else (lhs[z - 1][1] + r)
  15. if (cy > L):
  16. print "BANG!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  17. return "oops"
  18. coords[i] = (cx,cy)
  19. z2 = z + 1
  20. while (z2 < len(lhs)) and (lhs[z2][1] <= cy + r):
  21. z2 += 1
  22. lhs = [v for v in lhs if v[0] >= cx + r] + ([(cx+r,0)] if cy == 0 else []) + [(cx + r, cy + r)] + [v for v in lhs if v[1] > cy + r]
  23. break
  24. if (coords[i] == (-1,-1)):
  25. print "BANG!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  26. return "oops"
  27. return " ".join([str(d) for c in coords for d in c])
  28.  
  29. if __name__ == "__main__":
  30. from GCJ import GCJ
  31. GCJ(parse, solve, "/Users/lpebody/gcj/2012_2/b", "B").run()
  32.  
  33.  
  34.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty