fork download
  1. def parse(inFile):
  2. return tuple(inFile.getInts() + [inFile.getInts()])
  3.  
  4. def solve((R,K,N,groups)):
  5. i = 0
  6. pos = 0
  7. money = 0
  8. if (K > sum(groups)):
  9. K = sum(groups)
  10. cache = [[-1,-1] for ij in xrange(N)]
  11. while (i < R):
  12. if (cache[pos][0] == -1):
  13. cache[pos] = [i, money]
  14. else:
  15. [i2, money2] = cache[pos]
  16. repeats = (R - i - 1) / (i - i2)
  17. if (repeats >= 0):
  18. i += repeats * (i - i2)
  19. money += repeats * (money - money2)
  20. cache = [[-1,-1] for ij in xrange(N)]
  21. people = 0
  22. while (people + groups[pos] <= K):
  23. people += groups[pos]
  24. pos += 1
  25. if (pos == N):
  26. pos = 0
  27. money += people
  28. i += 1
  29. return money
  30.  
  31. if __name__ == "__main__":
  32. from GCJ import GCJ
  33. GCJ(parse, solve, "/Users/lpebody/gcj/2010_q/", "c").run()
  34.  
  35.  
  36.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty