fork download
  1. from typing import List
  2.  
  3.  
  4. def getMinProblemCount(N: int, S: List[int]) -> int:
  5. mods_3 = [False] * 3
  6. has_one = 1 in S
  7. max_score = max(S)
  8. max_score_multiple_3 = 0
  9.  
  10. for score in S:
  11. if score % 3 == 0:
  12. max_score_multiple_3 = max(max_score_multiple_3, score)
  13. mods_3[score % 3] = True
  14.  
  15. if max_score % 3 == 0 and mods_3[1] and mods_3[2]:
  16. return int(max_score / 3) + 1
  17.  
  18. if not has_one and mods_3[1] and mods_3[2] and max_score_multiple_3 != 3 * int(max_score / 3):
  19. return int(max_score / 3) + 2 - (1 if max_score % 3 == 1 else 0)
  20.  
  21. return int(max_score / 3) + (1 if mods_3[1] else 0) + (1 if mods_3[2] else 0)
  22.  
  23.  
  24. if __name__ == '__main__':
  25.  
  26. SAMPLES = [
  27. (11, [1,4,2,3,1,4,5,1,5,1,6]), # -> 3
  28. (4, [4, 3, 3, 4]), # -> 2
  29. (4, [2, 4, 6, 8]), # -> 4
  30. (1, [8]), # -> 3
  31. (5, [9,6,3,2,1])
  32. ]
  33.  
  34. for sample in SAMPLES:
  35. print(getMinProblemCount(*sample))
Success #stdin #stdout 0.19s 16712KB
stdin
Standard input is empty
stdout
3
2
4
3
4