fork download
  1. def parse(inFile):
  2. [N,M] = inFile.getInts()
  3. boxes = inFile.getInts()
  4. toys = inFile.getInts()
  5. boxes = [boxes[2*i:2*i+2] for i in xrange(N)]
  6. toys = [toys[2*i:2*i+2] for i in xrange(M)]
  7. return (boxes, toys)
  8.  
  9. def solve((boxes, toys)):
  10. B = len(boxes)
  11. T = len(toys)
  12. a = [[0 for i in xrange(B+1)] for j in xrange(T+1)]
  13. for t in xrange(T):
  14. for b in xrange(B):
  15. a[t+1][b+1] = max(a[t+1][b],a[t][b+1])
  16. if (boxes[b][1] == toys[t][1]):
  17. k = boxes[b][1]
  18. bs = [[z,boxes[z][0]] for z in xrange(b,-1,-1) if boxes[z][1] == k]
  19. ts = [[z,toys[z][0]] for z in xrange(t,-1,-1) if toys[z][1] == k]
  20. for j in xrange(1,len(bs)):
  21. bs[j][1] += bs[j-1][1]
  22. for j in xrange(1,len(ts)):
  23. ts[j][1] += ts[j-1][1]
  24. a[t+1][b+1] = max(a[t+1][b+1],max([min(t0[1],b0[1])+a[t0[0]][b0[0]] for t0 in ts for b0 in bs]))
  25. return a[-1][-1]
  26.  
  27. if __name__ == "__main__":
  28. from GCJ import GCJ
  29. GCJ(parse, solve, "/Users/lpebody/gcj/setup/", "c").run()
  30.  
  31.  
  32.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty