구현 문제입니다. 벨트와 로봇을 조건대로 고려하여 구현하였습니다.
rotate를 이용해서 편리하게 1칸씩 이동하였고, 벨트 위에 robot이 있을 경우 다음 벨트로 이동할 수 있는 경우 다음 벨트의 내구도를 -1씩 해주었습니다.
from collections import deque
N, K = map(int, input().split())
belt = deque(list(map(int, input().split())))
robot = deque([0] * N)
result = 0
while belt.count(0) < K:
belt.rotate(1)
robot.rotate(1)
robot[-1] = 0
if sum(robot):
for idx in range(N - 2, -1, -1):
if robot[idx] and not robot[idx + 1] and belt[idx + 1]:
belt[idx + 1] -= 1
robot[idx + 1], robot[idx] = 1, 0
robot[-1] = 0
if not robot[0] and belt[0]:
robot[0] = 1
belt[0] -= 1
result += 1
print(result)
'알고리즘' 카테고리의 다른 글
백준_유레카이론 (0) | 2021.05.05 |
---|---|
백준_14888 (0) | 2021.04.25 |
백준_12026 (0) | 2021.04.11 |
프로그래머스_등굣길 (0) | 2021.04.11 |
프로그래머스_주식가격 (0) | 2021.04.04 |