fork download
  1. def parse(inFile):
  2. return [inFile.getInts() for i in xrange(inFile.getInt())]
  3.  
  4. def solve(levels):
  5. INFINITY = 2 * len(levels) + 1
  6. starrating = 0
  7. levelsDone = 0
  8. justCantDoIt = False
  9. while (len(levels) > 0):
  10. score = sum([2 if level[0] < INFINITY else 1 for level in levels if level[1] <= starrating])
  11. levelsDone += len([level for level in levels if level[1] <= starrating])
  12. levels = [level for level in levels if level[1] > starrating]
  13. starrating += score
  14. if (len([level for level in levels if level[1] <= starrating])):
  15. continue
  16. if len(levels) == 0:
  17. break
  18. if len([level for level in levels if level[0] <= starrating]) == 0:
  19. justCantDoIt = True
  20. break
  21. holder = -1
  22. for levelIndex in xrange(len(levels)):
  23. if levels[levelIndex][0] <= starrating:
  24. if (holder == -1) or (levels[levelIndex][1] > levels[holder][1]):
  25. holder = levelIndex
  26. levels[holder][0] = INFINITY
  27. starrating += 1
  28. levelsDone += 1
  29. if justCantDoIt:
  30. return "Too Bad"
  31. else:
  32. return levelsDone
  33.  
  34. if __name__ == "__main__":
  35. from GCJ import GCJ
  36. GCJ(parse, solve, "/Users/lpebody/gcj/2012_1a/", "b").run()
  37.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty