def pageCount(n, p):
# 처음부터 시작할 때 : 0, 2, 4...
# 끝에서 시작할 때 : n // 2
# p가 있는 페이지 : p // 2
# 거리차를 구해서 min 출력
last_page = n // 2
current_page = p // 2
first_page = 0
if last_page - current_page > current_page - first_page:
return current_page - first_page
else:
return last_page - current_page
def main():
n = int(input())
p = int(input())
result = pageCount(n, p)
print(result)
if __name__ == '__main__':
main()
'HackerRank Algorithm' 카테고리의 다른 글
[HackerRank] 15. Diagonal Difference (0) | 2020.03.09 |
---|---|
[HackerRank] 14. Divisible Sum pairs (0) | 2020.03.09 |
[HackerRank] 12. Finding the percentage (0) | 2020.03.09 |
[HackerRank] 11. Floor, Ceil and Rint (0) | 2020.03.09 |
[HackerRank] 10. Granding Students (0) | 2020.03.09 |
댓글