|
| 1 | +def diving_minigame(intervals): |
| 2 | + allowed_extra = 10 |
| 3 | + curr_breath = 10 |
| 4 | + for eachinterval in intervals: |
| 5 | + if curr_breath == 0: |
| 6 | + return False |
| 7 | + elif eachinterval >= 0 and curr_breath < 10: |
| 8 | + if allowed_extra > 0: |
| 9 | + extra_off = abs(curr_breath - 10) |
| 10 | + curr_breath += extra_off if extra_off <= 4 else 4 |
| 11 | + allowed_extra -= extra_off if extra_off <= 4 else 4 |
| 12 | + elif eachinterval < 0: |
| 13 | + curr_breath -= 2 |
| 14 | + return curr_breath != 0 |
| 15 | + |
| 16 | + |
| 17 | +if __name__ == '__main__': |
| 18 | + diving_minigame([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) # True) |
| 19 | + diving_minigame([-5, -15, -4, 0, 5]) # True) |
| 20 | + diving_minigame([0, -4, 0, -4, -5, -2]) # True) |
| 21 | + diving_minigame([-4, -3, -4, -3, 5, 2, -5, -20, -42, -4, 5, 3, 5]) # True) |
| 22 | + |
| 23 | + diving_minigame([-3, -6, -2, -6, -2]) # False) |
| 24 | + diving_minigame([-4, -5, -2, -7, 2, -1000, -2000, -1]) # False) |
| 25 | + diving_minigame([1, 2, 1, 2, 1, 2, 1, 2, 1, -3, -4, -5, -3, -4]) # False) |
| 26 | + diving_minigame([-5, -5, -5, -5, -5, 2, 2, 2, 2, 2, 2, 2, 2]) # False) |
0 commit comments