Created
April 23, 2020 09:08
-
-
Save inspirit941/7d012d781f8fdac87830ef6a9541676c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# UTF-8 encoding when using korean | |
import sys | |
n = int(sys.stdin.readline()) | |
arr = list(map(int, sys.stdin.readline().split())) | |
# 보유해야 할 힘의 양 | |
answer = 0 | |
# 뒤에서부터 계산하면 | |
for idx in range(len(arr)-1, 0, -1): | |
# 한 칸 이동하는 데 필요한 p의 양 | |
need_p = arr[idx] - arr[idx-1] | |
# 햔제 보유한 힘의 양보다 많이 필요하면 answer 값 업데이트 | |
answer = max(need_p, answer) | |
# p손실 보충을 위한 값 | |
answer += 1 | |
# 0에서 첫 번째 돌까지 이동하는 것 계산 | |
need_p = arr[0] | |
answer = max(need_p, answer) | |
# 만약 첫 번째 돌까지 이동하는 데 필요한 p값이 제일 클 경우, p손실 보충을 위해 +1 | |
if answer == need_p: | |
answer += 1 | |
print(answer) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment